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 <iostream> #include <string> using namespace std; int a[2][100000]; char stringList[9]; void printfInt(int number) { for (int i = 7; i >= 0; i--) { if ( i == 3) { stringList[i] = '-'; } else { int b = number % 10; stringList[i] = b + '0'; number = number / 10; } } stringList[8] = '\0'; cout<<stringList; } int changeStringIntoInt(string s) { int number = 0;; int si; for (int i = 0; i < s.length(); i++) { if ((s[i] >= '0') && (s[i] <= '9')) { number = number * 10 + (s[i] - '0'); } else if (s[i] == '-') { } else { switch (s[i]) { case 'A': case 'B': case 'C': si = 2; break; case 'D': case 'E': case 'F': si = 3; break; case 'G': case 'H': case 'I': si = 4; break; case 'J': case 'K': case 'L': si = 5; break; case 'M': case 'N': case 'O': si = 6; break; case 'P': case 'R': case 'S': si = 7; break; case 'T': case 'U': case 'V': si = 8; break; case 'W': case 'X': case 'Y': si = 9; break; default: ; } number = number * 10 + si; } } return number; } int main() { int n; string s; cin>>n; while (n) { cin>>s; int number = changeStringIntoInt(s); int i = 0; while (a[0][i]) { if (number == a[0][i]) { a[1][i] ++; break; } else i++; } if (a[0][i] == 0) { int j = 0; for (j = i - 1;j >= -1; j--) { if (a[0][j] > number) { a[0][j + 1] = a[0][j]; a[1][j + 1] = a[1][j]; } else { a[0][j + 1] = number; a[1][j + 1] = 1; break; } } } n--; } int i = 0; while(a[0][i]) { if (a[1][i] > 1) { printfInt(a[0][i]); cout<<" "<<a[1][i]<<endl; } else { } i++; } return 1; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator