Description
lc是一名虫子老师,刚刚教完一届,准备带新的一年级小虫子。你手上有一份他们自己登记的学号名单,学号的标准格式为:xxx-xxxx(x为数字),例如000-0000。但是小虫子们很健忘,老是不记得自己登记学号了没有,所以他们经常重复登记自己的学号,而且每次登记的学号格式都有可能不一样。虫子校长为了刁难老师,允许他们在数字之间的任意位置添加“-”,例如,3-10-10-10的标准格式是310-1010。校长还有一个更恶毒的手段:他给每只小虫子发一个密码本,小虫子们可以按密码本改自己的学号,密码本如下:
A, B, 和C 表示 2
D, E, 和F 表示 3
G, H, 和I表示4
J, K, 和L表示5
M, N, 和O表示6
P, R, 和S表示7
T, U, 和V表示8
W, X, 和Y表示9
Q和Z不表示任何数字。
例如:TUT-GLOP的标准格式是888-4567,310-GINO的标准格式是310-4466。如果两个学号的标准格式是相同的,那么他们是同一只小虫子登记的。由于lc太愚蠢了,他想找你帮他找出重复的学号和重复的次数。
Input
第一行一个整数n(0≤n≤100000)表示名单上学号的总个数,接下来你行每行一个学号(不包含Q和Z),每个学号中刚好有7个数字或字母。
Output
对于每个出现重复的学号产生一行输出,输出是学号的标准格式紧跟一个空格然后是它的重复次数。如果存在多个重复的学号,则按照学号的字典序升序输出。
Sample Input
12
4873279
ITS-EASY
888-4567
3-10-10-10
888-GLOP
TUT-GLOP
967-11-11
310-GINO
F101010
888-1200
-4-8-7-3-2-7-9-
487-3279
Sample Output
310-1010 2
487-3279 4
888-4567 3
典型的桶排序。
AC Code:
#include <iostream>
#include <string>
#define SIZE 10000000
using namespace std;
int a[SIZE];
int c[127];
string s;
void start(void)
{
#if 0
A, B, ?C ?? 2
D, E, ?F ?? 3
G, H, ?I??4
J, K, ?L??5
M, N, ?O??6
P, R, ?S??7
T, U, ?V??8
W, X, ?Y??9
#endif
int i;
c['Q'] = c['Z'] = c['-'] = -1;
c['0'] = 0;
c['1'] = 1;
c['A'] = c['B'] = c['C'] = c['2'] = 2;
c['D'] = c['E'] = c['F'] = c['3'] = 3;
c['G'] = c['H'] = c['I'] = c['4'] = 4;
c['J'] = c['K'] = c['L'] = c['5'] = 5;
c['M'] = c['N'] = c['O'] = c['6'] = 6;
c['P'] = c['R'] = c['S'] = c['7'] = 7;
c['T'] = c['U'] = c['V'] = c['8'] = 8;
c['W'] = c['X'] = c['Y'] = c['9'] = 9;
return;
}
int main(int argc, char** argv)
{
int n, i, temp;
cin >> n;
start();
while (n--)
{
temp = 0;
cin >> s;
for (i = 0; i < s.size(); i++)
{
if (c[s[i]] == -1)
{
continue;
}
temp *= 10;
temp += c[s[i]];
}
a[temp]++;
}
for (i = 0; i < SIZE; i++)
{
if (a[i] > 1)
{
printf("%d-%d %d\n", i / 10000, i % 10000, a[i]);
}
}
return 0;
}
附加:这是原题(gdgzoi改了一下)
487-3279
Time Limit: 2000MS
Memory Limit: 30000K
Total Submissions: 59071
Accepted: 9916
Description
Businesses like to have memorable telephone numbers. One way to make a telephone number memorable is to have it spell a memorable word or phrase. For example, you can call the University of Waterloo by dialing the memorable TUT-GLOP. Sometimes only part of the number is used to spell a word. When you get back to your hotel tonight you can order a pizza from Gino's by dialing 310-GINO. Another way to make a telephone number memorable is to group the digits in a memorable way. You could order your pizza from Pizza Hut by calling their ``three tens'' number 3-10-10-10.
The standard form of a telephone number is seven decimal digits with a hyphen between the third and fourth digits (e.g. 888-1200). The keypad of a phone supplies the mapping of letters to numbers, as follows:
A, B, and C map to 2
D, E, and F map to 3
G, H, and I map to 4
J, K, and L map to 5
M, N, and O map to 6
P, R, and S map to 7
T, U, and V map to 8
W, X, and Y map to 9
There is no mapping for Q or Z. Hyphens are not dialed, and can be added and removed as necessary. The standard form of TUT-GLOP is 888-4567, the standard form of 310-GINO is 310-4466, and the standard form of 3-10-10-10 is 310-1010.
Two telephone numbers are equivalent if they have the same standard form. (They dial the same number.)
Your company is compiling a directory of telephone numbers from local businesses. As part of the quality control process you want to check that no two (or more) businesses in the directory have the same telephone number.
Input
The input will consist of one case. The first line of the input specifies the number of telephone numbers in the directory (up to 100,000) as a positive integer alone on the line. The remaining lines list the telephone numbers in the directory, with each number alone on a line. Each telephone number consists of a string composed of decimal digits, uppercase letters (excluding Q and Z) and hyphens. Exactly seven of the characters in the string will be digits or letters.
Output
Generate a line of output for each telephone number that appears more than once in any form. The line should give the telephone number in standard form, followed by a space, followed by the number of times the telephone number appears in the directory. Arrange the output lines by telephone number in ascending lexicographical order. If there are no duplicates in the input print the line:
No duplicates.
Sample Input
12
4873279
ITS-EASY
888-4567
3-10-10-10
888-GLOP
TUT-GLOP
967-11-11
310-GINO
F101010
888-1200
-4-8-7-3-2-7-9-
487-3279
Sample Output
310-1010 2
487-3279 4
888-4567 3
Source
East Central North America 1999