487-3279 hoj 模拟AC
来源:互联网 发布:福田吉兆知乎 编辑:程序博客网 时间:2024/05/18 21:42
/*之前写的在poj1002上AC了,但是在HOJ上过不了,现在又写了一遍,在HOJ 上过了。一个是字符串排序的写法,可以当模板用。其余都是细节问题。*/#include <stdio.h>#include <cstring>#include <iostream>#include <algorithm>using namespace std;const int maxn=100001;int cmp(const void* _a,const void* _b){ char* a=(char*)_a; char* b=(char*)_b; return strcmp(a,b);}char getnum(char c){ if(c>='A'&&c<='C') return '2'; else if(c<='F') return '3'; else if(c<='I') return '4'; else if(c<='L') return '5'; else if(c<='O') return '6'; else if(c<='S') return '7'; else if(c<='V') return '8'; else if(c<='Y') return '9';}char temp[maxn][50];int main(){ int t; int ca=0; scanf("%d",&t); while(t--) { int n,tt; if(ca>0) printf("\n"); ca=1; memset(temp,0,sizeof(temp)); scanf("%d",&n); getchar(); char op[50]; char t[50]; memset(t,0,sizeof(t)); for(int i=0; i<n; i++) { gets(op); tt=0; for(int j=0; j<strlen(op); j++) { if(op[j]=='-') continue; if(op[j]>='A'&&op[j]<='Z') t[tt++]=getnum(op[j]); else t[tt++]=op[j]; } t[tt]='\0'; strcpy(temp[i],t); } qsort(temp,n,sizeof(temp[0]),cmp); int num=1; bool flag=false; for(int i=0; i<n; i++) { if(strcmp(temp[i],temp[i+1])==0) { num++; continue; } else { if(num>1) { flag=true; for(int j=0; j<3; j++) printf("%c",temp[i][j]); printf("-"); for(int j=3; j<strlen(temp[i]); j++) printf("%c",temp[i][j]); printf(" %d\n",num); } num=1; } } if(!flag) printf("No duplicates.\n"); } return 0;}