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 |
哪位大神,给小弟一些错误的测试数据,不胜感激,总是wa!#include <iostream> #include <string> #include <algorithm> using namespace std; string str[100000]; bool cmp(const string& s1,const string& s2); void printout(string s); bool isPrintout = false; int main() { int n = 0; cin >> n; for (int i = 0;i < n;++i) { cin >> str[i]; } for (int i = 0;i < n; ++i) { int len = str[i].length(); for (int j = 0; j < len; ++j) { int position = str[i].find("-"); if (position != string::npos) { str[i].erase(position,1); } } str[i] = str[i].substr(0,7); } for (int i = 0;i < n;++i) { for (int j = 0;j < str[i].length(); ++j) { if (str[i][j] == 'A' || str[i][j] == 'B'|| str[i][j] == 'C') { str[i][j] = '2'; continue; } if (str[i][j] == 'D' || str[i][j] == 'E'|| str[i][j] == 'F') { str[i][j] = '3'; continue; } if (str[i][j] == 'G' || str[i][j] == 'H'|| str[i][j] == 'I') { str[i][j] = '4'; continue; } if (str[i][j] == 'J' || str[i][j] == 'K'|| str[i][j] == 'L') { str[i][j] = '5'; continue; } if (str[i][j] == 'M' || str[i][j] == 'N'|| str[i][j] == 'O') { str[i][j] = '6'; continue; } if (str[i][j] == 'P' || str[i][j] == 'Q'|| str[i][j] == 'S') { str[i][j] = '7'; continue; } if (str[i][j] == 'T' || str[i][j] == 'U'|| str[i][j] == 'V') { str[i][j] = '8'; continue; } if (str[i][j] == 'W' || str[i][j] == 'X'|| str[i][j] == 'Y') { str[i][j] = '9'; continue; } } } sort(str,str+n,cmp); int counter = 1; for (int i = 1; i < n; ++i) { if (!str[i].compare(str[i-1])) { counter++; } else if (counter >= 2) { printout(str[i-1]); cout << " " << counter << endl; counter = 1; } } if (counter >= 2) { printout(str[n-1]); cout << " " << counter << endl; } if (!isPrintout) { cout << "No duplicates." << endl; } return 0; } void printout(string s) { for (int i = 0; i < s.length(); ++i) { if(i == 3) cout << "-"; cout << s[i]; } isPrintout = true; } bool cmp(const string& s1,const string& s2) { return s1.compare(s2)<0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator