poj 1002 487-3279
2010-07-12 21:27
447 查看
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 135796 | Accepted: 23073 |
思想:将接收到得字符串进行处理,使正常化之后,再对他们进行排序(本来我是想一个一个的匹配然后用一个数组记录下相同字符串并用一个字符串记录相同的个数,后来发现还是这个方法比高明),排序之后相同的肯定排在一起,然后对相邻的两个字符串进行比较,如果相等让i++,if(i-j)>1表名有重复的字符串,此时对本字符串输出,并输出重复的个数i-j.
代码:
#include<stdio.h> #include<string.h> #include<stdlib.h> char b[]="22233344455566677778889999"; char c[10];char d[100000][9]; int compare(const void *e1,const void *e2) { return strcmp((char *)e1,(char *)e2); }; void tran(char a[]) { int i,j=0; for(i=0;a[i]!='\0';i++) { if(a[i]=='-') continue; if(a[i]>='A' && a[i]<='Z') c[j]=b[a[i]-'A']; else c[j]=a[i]; j++; if(j==3) { c[j]='-'; j++; } } c[j]='\0'; } int main() { int i,j; char a[50];int n,count=0,mark=1,m; scanf("%d",&n); m=n; while(m--) { scanf("%s",a); tran(a); strcpy(d[count++],c); } qsort(d,n,sizeof(d[0]),compare); for(i=0;i<n;) { j=i; i++; while(strcmp(d[i],d[j])==0 && i<n) i++; if(i-j>1) { printf("%s %d\n",d[j],i-j); mark=0; } } if(mark) printf("No duplicates.\n"); return 0; }
相关文章推荐
- poj 1002 487-3279
- 487-3279[POJ1002]
- poj 1002 487-3279
- 【POJ】1002 - 487-3279
- POJ 1002 487-3279
- [POJ 1002] 487-3279 C++解题报告
- poj 1002 487-3279
- POJ 1002 487-3279
- POJ 1002 487-3279 G++
- POJ-1002 487-3279
- poj_1002_487-3279
- POJ 1002 487-3279(map应用)
- POJ 1002 487-3279
- (POJ 1002) 487-3279
- POJ解题报告——1002 487-3279
- POJ-1002 487-3279
- [POJ_1002]487-3279
- poj 1002 487-3279之map解法
- poj1002 487-3279 ——水题
- POJ 1002 487-3279 与二维数组的快速排序