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<algorithm> #include<cstdlib> #include<cstdio> #include<cctype> #include<cstring> using namespace std; const int N = 110000; inline char translate(char c) { //这个转换函数应该用数组实现。 char ret = c; switch(c) { case 'A': case 'B' : case 'c': ret = '2'; break; case 'D':case 'E':case 'F': ret = '3'; break; case 'G':case 'H':case 'I': ret = '4'; break; case 'J':case 'K': case 'L': ret = '5'; break; case 'M':case 'N': case 'O': ret = '6'; break; case 'P':case 'R': case 'S': ret = '7'; break; case 'T':case 'U': case 'V': ret = '8'; break; case 'W':case 'X': case 'Y': ret = '9'; break; } return ret; } //CMP的功能: 前者大于后者 int cmp(const void *a, const void *b) { return strcmp(*(char **)a, *(char **)b); } int main() { int n; cin>>n; char nums[N][8]; int count; for(int i = 0; i < n; i++) { int k = 0; char c; while(k != 7) { scanf("%c", &c); if(isalnum(c)) nums[i][k++] = translate(c); } nums[i][k] = '\0'; } //Start to sort; use quicksort char *numsptr[N]; for(int i = 0; i < n; i++) numsptr[i] = nums[i]; qsort(numsptr, n, sizeof(char *),cmp); // for(int i = 0; i < n; i++) printf("%s\n", numsptr[i]); int i = 0, dup = 1; bool existdup = false; for(int i = 1; i < n; i++) { if(strcmp(numsptr[i],numsptr[i - 1]) == 0) dup++; else if((strcmp(numsptr[i],numsptr[i - 1]) != 0) && dup > 1) { existdup = true; printf("%c%c%c-%c%c%c%c %d\n", numsptr[i - 1][0],numsptr[i - 1][1],numsptr[i - 1][2],numsptr[i - 1][3],numsptr[i - 1][4],numsptr[i - 1][5],numsptr[i - 1][6], dup); dup = 1; } } if(!existdup)cout<<"No duplicates."<<endl; } //实在是不明白自己到底错在哪里? Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator