Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
几点注意及提示,附上我的代码1. 每行输入的字符串长度可能很长,char str[20]就WA了,char str[100]就AC了。 2. 将每个电话号码转成数字(num<10^7),然后++ map[num] 3. 输入量很大,建议采用scanf或gets 4. 输出可以采用这种方式:printf("%03d-%04d %d\n", it->first/10000, it->first%10000, it->second); G++ 600+ms #include <iostream> #include <string> #include <map> #include <iterator> #include <stdio.h> #include <string.h> #include <algorithm> using namespace std; inline int c(const char & ch) { switch (ch) { case '0': return 0; case '1': return 1; case 'A': case 'B': case 'C': case '2': return 2; case 'D': case 'E': case 'F': case '3': return 3; case 'G': case 'H': case 'I': case '4': return 4; case 'J': case 'K': case 'L': case '5': return 5; case 'M': case 'N': case 'O': case '6': return 6; case 'P': case 'R': case 'S': case '7': return 7; case 'T': case 'U': case 'V': case '8': return 8; case 'W': case 'X': case 'Y': case '9': return 9; } return -1; } map<int, int> mp; int main() { char str[100]; int res, cas; scanf("%d", &cas); while (getchar() != '\n'); while (cas --) { gets(str); res = 0; for (int i = 0; str[i]; ++ i) { if (str[i] != '-') { res = res * 10 + c(str[i]); } } ++ mp[res]; } bool b = 0; for (map<int, int>::const_iterator it = mp.begin(); it != mp.end(); ++ it) { if (it->second > 1) { b = 1; printf("%03d-%04d %d\n", it->first/10000, it->first%10000, it->second); } } if (!b) { puts("No duplicates."); } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator