Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 273309 | Accepted: 48749 |
Description
Input
Output
Sample Input
12 4873279 ITS-EASY 888-4567 3-10-10-10 888-GLOP TUT-GLOP 967-11-11 310-GINO F101010 888-1200 -4-8-7-3-2-7-9- 487-3279
Sample Output
310-1010 2 487-3279 4 888-4567 3
这个题目是个大模拟,利用映射,模拟求解
#include <stdio.h> #include <string.h> #include <algorithm> using namespace std; const int N = 1e5+5; struct point{ char x[100]; }pp[N]; bool cmp(struct point a,struct point b){ return strcmp(a.x,b.x)<0; } int s[100]; void init(){ s['0']='0'; s['1']='1'; s['2']=s['A']=s['B']=s['C']='2'; s['3']=s['D']=s['E']=s['F']='3'; s['4']=s['G']=s['H']=s['I']='4'; s['5']=s['J']=s['K']=s['L']='5'; s['6']=s['M']=s['N']=s['O']='6'; s['7']=s['P']=s['R']=s['S']='7'; s['8']=s['T']=s['U']=s['V']='8'; s['9']=s['W']=s['X']=s['Y']='9'; } int main(){ int n,i,j,k; char p[100]; init(); while(~scanf("%d",&n)){ for(i=0;i<n;i++){ scanf("%s",&p); int count=0; for(j=0;p[j]!='\0';j++){ if(count==3) pp[i].x[count++]='-'; if(p[j]!='-') pp[i].x[count++]=s[p[j]]; } pp[i].x[count]='\0'; } sort(pp,pp+n,cmp); // for(i=0;i<n;i++) // printf("%s\n",pp[i].x); // int ans; int flag=1; for(i=0;i<n;i++){ ans=1; while(strcmp(pp[i].x,pp[i+1].x)==0){ i++; ans++; } if(ans>1) { printf("%s %d\n",pp[i-1].x,ans); flag=0; } } if(flag) printf("No duplicates.\n"); } return 0; }