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 |
怎么老是Wrong Answer,大侠们帮我看一下吧#include <cstdlib> #include <iostream> #include <map> using namespace std; void convert(string pn, string& result) { result = ""; char r[9]; int rcount = 0; r[8] = 0; for (int i = 0; i < pn.length(); i++) { char c = pn[i]; char nc; switch(c) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': nc = c; break; case 'A': case 'B': case 'C': nc = '2'; break; case 'D': case 'E': case 'F': nc = '3'; break; case 'G': case 'H': case 'I': nc = '4'; break; case 'J': case 'K': case 'L': nc = '5'; break; case 'M': case 'N': case 'O': nc = '6'; break; case 'P': case 'R': case 'S': nc = '7'; break; case 'T': case 'U': case 'V': nc = '8'; break; case 'W': case 'X': case 'Y': nc = '9'; break; default: nc = 0; } if (nc != 0) { r[rcount] = nc; rcount++; if (rcount == 3) { r[rcount] = '-'; rcount++; } if (rcount == 8) break; } } result = r; } int main(int argc, char *argv[]) { int numPhones = 0; cin >> numPhones; int i = 0; string pn, result; map<string, int> countMap; for (i = 0; i < numPhones; i++) { cin >> pn; convert(pn, result); countMap[result]++; } if (countMap.size() == 0) cout << "No duplicates."; else { map<string,int>::iterator iter; for( iter = countMap.begin(); iter != countMap.end(); iter++ ) { if ((int)(iter->second) > 1) cout << iter->first << " " << iter->second << endl; } } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator