ZCMU-1770-打字

1770: 打字

Time Limit: 1 Sec   Memory Limit: 128 MB
Submit: 80   Solved: 15
[ Submit][ Status][ Web Board]

Description

We all use cell phone today. And we must be familiar with the intelligent English input method on the cell phone. To be specific, the number buttons may correspond to some English letters respectively, as shown below:
  2 : a, b, c    3 : d, e, f    4 : g, h, i    5 : j, k, l    6 : m, n, o    
  7 : p, q, r, s  8 : t, u, v    9 : w, x, y, z
  When we want to input the word “wing”, we press the button 9, 4, 6, 4, then the input method will choose from an embedded dictionary, all words matching the input number sequence, such as “wing”, “whoi”, “zhog”. Here comes our question, given a dictionary, how many words in it match some input number sequences?

Input

 First is an integer T, indicating the number of test cases. Then T block follows, each of which is formatted like this:
  Two integer N (1 <= N <= 5000), M (1 <= M <= 5000), indicating the number of input number sequences and the number of words in the dictionary, respectively. Then comes N lines, each line contains a number sequence, consisting of no more than 6 digits. Then comes M lines, each line contains a letter string, consisting of no more than 6 lower letters. It is guaranteed that there are neither duplicated number sequences nor duplicated words.

Output

 For each input block, output N integers, indicating how many words in the dictionary match the corresponding number sequence, each integer per line.

Sample Input

1
3 5
46
64448
74
go
in
night
might
gn

Sample Output

3
2
0

【解析】
这道题的意思就是首先输入n组数组,然后输入一下我们需要进行统计这个操作能打印出多少字符的m,再输入有k个字
符。就是问在这k个字符当中我每次的操作能打印出几个。其实我们只要统计下字符能通过哪些操作打印出来就好了比
如go就可以通过46打印出来,in也是46,gn也是46所以46操作能打印出来的是3个字符。我们可以建一个数组把每个字
符对应的操作数存储起来。然后最后我们就可以直接进行查询,这个操作数有没有值。此处是模仿他人代码
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <iostream>
#include <map>
using namespace std;
int a[28]={2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,7,8,8,8,9,9,9,9};//每个字符对应的操作
int b[100000];
int c[6000];
char s[100000];
int main()
{
	int t,i,j;
	scanf("%d",&t);
	int n,m;
    while(t--)
    {
        scanf("%d%d",&n,&m);
		memset(b,0,sizeof(b));
		memset(c,0,sizeof(c));
		for(i=0;i<n;i++)
        {
            scanf("%d",&c[i]);//输入操作数
        }
		for(i=0;i<m;i++)
        {
        	scanf("%s",s);
			int sum=0;
            for(j=0;j<strlen(s);j++)
				sum=sum*10+a[s[j]-97];//计算每个字符的操作数
			b[sum]++;
        }
        for(i=0;i<n;i++)
        {
        printf("%d\n",b[c[i]]);//在操作数中输出值
        }
    }
    return 0;
}

<think>好的,用户想查询ZCMU OJ 1318的题目详情或解题方法。首先,我需要确认自己是否了解这个题目。由于ZCMU OJ的题目可能不在我的训练数据中,我需要根据现有的引用信息进行推断,或者给出一般性的建议。 查看用户提供的引用,发现引用1提到了1614题涉及字符串替换和大小写处理,引用2是1489题关于数气球,引用3是1900题关于并查集的应用。这些信息可能帮助用户解决类似问题,但用户明确询问的是1318题,因此需要处理这个具体的问题。 首先,我需要检查是否有关于1318题的引用,但用户给出的引用中并没有直接提到1318。因此,可能需要建议用户通过题目编号查找或根据常见题型推测。例如,ZCMU的题目可能涉及数据结构、算法或字符串处理等。考虑到引用中的其他题目涉及字符串处理和并查集,1318可能属于类似类型。 接下来,我应该建议用户检查题目链接或提供更多细节,比如题目描述或输入输出样例,以便更准确地分析。同时,可以给出常见的解题思路,比如字符串处理、动态规划或图论算法,并参考现有引用中的类似题目,如字符串处理要注意大小写(引用1),数气球可能涉及计数或哈希表(引用2),并查集用于处理连通性问题(引用3)。 如果用户无法提供更多信息,可以建议搜索ZCMU OJ的在线资源或论坛,比如官方网站、GitHub题解或相关讨论区。此外,提供通用的解题步骤,如分析输入输出、确定算法、处理边界情况等,可能对用户有帮助。 最后,生成相关问题,引导用户进一步提问或提供更多细节,以便更精准地解答。</think>根据现有资料,ZCMU OJ 1318的具体题目内容未在提供的引用中直接提及。以下是帮助您解决此类编程题目的通用方法及建议: ### 常见解题思路(适用于ZCMU OJ题型) 1. **字符串处理** 若涉及字符串操作(如引用[^1]中1614题的替换和大小写处理): ```python # 示例:字符串替换时保留大小写标记 original = "HelloWorld" positions = [0 if c.isupper() else 1 for c in original] # 记录大小写位置 modified = original.lower().replace("world", "Python") result = "".join([c.upper() if positions[i]==0 else c for i,c in enumerate(modified)]) ``` 2. **并查集应用** 若涉及连通性问题(如引用[^3]中1900题的多米诺骨牌): ```python class UnionFind: def __init__(self, n): self.parent = list(range(n+1)) def find(self, x): if self.parent[x] != x: self.parent[x] = self.find(self.parent[x]) return self.parent[x] def union(self, x, y): self.parent[self.find(y)] = self.find(x) ``` 3. **计数与统计** 若涉及数值统计(如引用[^2]中1489题的气球计数): ```python from collections import defaultdict def count_balloons(arr): counter = defaultdict(int) for num in arr: counter[num] += 1 return max(counter.values()) if counter else 0 ``` ### 建议步骤 1. **获取题目描述** 访问ZCMU OJ官网或通过题目编号搜索获取1318题的输入输出样例及具体要求。 2. **分析问题类型** - 若涉及字符串:注意大小写处理、特殊符号过滤 - 若涉及数学:推导公式或使用动态规划 - 若涉及图论:构建邻接表或应用DFS/BFS 3. **参考相似题目** 如引用的字符串替换题需额外记录大小写位置,这种技巧可推广到其他需要保留原始格式的场景。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值