南邮 OJ 1464 Text Messaging

来源:互联网 发布:什么软件可以泡妞 编辑:程序博客网 时间:2024/06/08 03:46

Text Messaging

时间限制(普通/Java) : 1000 MS/ 3000 MS          运行内存限制 : 65536 KByte
总提交 : 65            测试通过 : 38 

比赛描述

You can type alphabets on a cell phone using numeric keypads using the following key mapping.

Numbers

Alphabets

2

abc

3

def

4

ghi

5

jkl

Numbers

Alphabets

6

mno

7

pqrs

8

tuv

9

wxyz

Since one numeric keypad represents many alphabets, on the standard system, the user must press the keypad many times to choose the right alphabet. For example to type the word “rat”, the user must press 77728. (777 to get “r”, 2 to get “a”, and 8 to get “t”.)

After the word prediction software, the user does not have to do that anymore. To type “rat” the user can type 728, and the prediction software would guess “rat” automatically. For another example, consider the word “cat.” To type that the user needs only press 228. We call the key sequence required to type a given word as its key sequence. Thus, the key sequence of “cat” is 228, and the key sequence of “rat” is 728.

However, this is not perfect because many words share the same key sequence. For example, “cat” and “bat” have the same key sequence 228.

Given a set of words, your task is to find out how many different key sequences needed to type any words in the set. For example if the set is {“rat”, “cat”, “bat”}, the number of different key sequences is 2, i.e., 228 and 728. 




输入

The first line of the input contains an integer (1 <= <= 6) denoting the number of test cases. After that test cases follow.

The first line of each test case contains an integer (1 <= <= 1,000) denoting the number of words. After that lines follows. Each line contains different word. Each word consists of only small English alphabets, and the maximum length of any words is at most 20 characters. 


输出

For any test case, your program should output an integer denoting the number of different key sequences. 


样例输入

2
3
cat
rat
bat
5
abcdefg
cccdddi
aaafefh
hello
world

样例输出

2
3

提示

In the first case, two sequences are 228 and 728. In the second case, the three sequences are 2223334, 43556, and 96753. 

用于NUPT ACM 2010 Personal Ranking Contest 5


题目来源

ACM-ICPC Thailand Southern Area Programming Contest 2010




#include<iostream>#include<string>#include<set>using namespace std;int main(){int a[26]={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};string s;int T,N,i,len;set<string> sSet;cin>>T;while(T--){sSet.clear();cin>>N;while(N--){cin>>s;len = (int)s.length();for(i=0; i<len; i++){s[i] = a[s[i]-'a'];}sSet.insert(s);}cout<<sSet.size()<<endl;}}






0 0
原创粉丝点击