POJ: 1002 487-3279
Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 324245 Accepted: 57280
时间和内存要求都不是特别严格,练手小题。
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
Accepted Source Code
5052K 1079MS
// 487-3279
/* Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 324226 Accepted: 57277 */
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cstring>
#include <iostream>
#include <map>
#include <string>
#include <utility>
#define dbg 0
using namespace std;
map<char, char> m1;
map<string, int> m2;
int main() {
m1['A'] = '2';
m1['B'] = '2';
m1['C'] = '2';
m1['D'] = '3';
m1['E'] = '3';
m1['F'] = '3';
m1['G'] = '4';
m1['H'] = '4';
m1['I'] = '4';
m1['J'] = '5';
m1['K'] = '5';
m1['L'] = '5';
m1['M'] = '6';
m1['N'] = '6';
m1['O'] = '6';
m1['P'] = '7';
m1['R'] = '7';
m1['S'] = '7';
m1['T'] = '8';
m1['U'] = '8';
m1['V'] = '8';
m1['W'] = '9';
m1['X'] = '9';
m1['Y'] = '9';
char str[1024];
#if dbg
printf("Hello.%d\n", 101);
FILE* fp;
fopen_s(&fp, "poj/build/p1002.si", "r");
if (fp == NULL) {
printf("ERROR LOADING FILE.\n");
return -1;
}
int cnt;
fgets(str, 1024, fp);
sscanf(str, "%d", &cnt);
// fscanf(fp, "%d", &cnt);
#else
int cnt;
gets(str);
sscanf(str, "%d", &cnt);
#endif
char res[9];
int eff; // 有效输出
for (int i = 0; i < cnt; i++) {
#if dbg
printf("%s", fgets(str, 1024, fp));
#else
gets(str);
#endif
eff = 0;
res[3] = '-';
res[8] = '\0';
if (strlen(str) >= 7) {
for (int j = 0; j < strlen(str); j++) {
char c = str[j];
if (eff == 3) {
// printf("-");
eff = 4;
}
if (c >= 'A' && c <= 'Z') {
// printf("%d", m1[str[j]]);
res[eff] = m1[c];
eff++;
} else if (c >= '0' && c <= '9') {
// printf("%c", str[j]);
res[eff] = c;
eff++;
}
}
}
m2[res] = m2[res] + 1;
#if dbg
printf("%s\n", res);
printf("%d\n", m2[res]);
#endif
map<string, int>::iterator it;
int effcnt = 0;
for (it = m2.begin(); it != m2.end(); it++) {
string s = it->first;
s = s.substr(0, 8);
#if 0
printf("%s, %d\n", s.data(), it->second);
#endif
if (s.size() == 8 && it->second > 1) {
effcnt++;
printf("%s %d\n", s.data(), it->second);
}
}
if (effcnt == 0) {
printf("No duplicates.\n");
}
return 0;
}