poj 1002 487-3279
2010-09-14 21:32
344 查看
http://acm.pku.edu.cn/JudgeOnline/problem?id=1002
自己琢磨出用qsort排字符串数组,虽然时间很多860ms 但是很有成就感
自己琢磨出用qsort排字符串数组,虽然时间很多860ms 但是很有成就感
#include<stdio.h> #include<string.h> #include<stdlib.h> int cmp(const void*a,const void*b){ return strcmp((char*)a,(char *)b); } int main(){ char s[100001][10],ch; int i,j,num,flag,flag1; int n; while(scanf("%d",&n)!=EOF){ j=0; getchar(); for(i=0;i<n;i++){ ch=getchar(); while(ch!='/n'){ switch(ch){ case 'A': case 'B': case 'C': ch='2';break; case 'D': case 'E': case 'F': ch='3';break; case 'G': case 'H': case 'I': ch='4';break; case 'J': case 'K': case 'L': ch='5';break; case 'M': case 'N': case 'O': ch='6';break; case 'P': case 'R': case 'S': ch='7';break; case 'T': case 'U': case 'V': ch='8';break; case 'W': case 'X': case 'Y': ch='9';break; } if(ch>='0'&&ch<='9'){ if(j==3){s[i][j]='-';j++;} s[i][j]=ch; j++; } ch=getchar(); } s[i][j]='/0'; j=0; } flag=flag1=0; qsort(s,n,sizeof(s[0]),cmp); flag=0;num=1; for(i=0;i<n-1;i++){ for(j=i+1;j,n;j++){ if(strcmp(s[i],s[j])==0){ i=j; flag=1; flag1=1; num++; } else break; } if(flag){printf("%s %d/n",s[i],num);flag=0;num=1;} } if(!flag1) printf("No duplicates./n"); } return 0; }
相关文章推荐
- [POJ_1002]487-3279
- poj每日一题之1002(487-3279)
- poj 1002 487-3279
- poj 1002 487-3279
- poj1002 487-3279
- POJ 1002_487-3279
- 【POJ】1002. 487-3279
- poj 1002:487-3279(水题,提高题 / hash)
- poj 1002 487-3279
- POJ 1002 487-3279 Trie解读
- poj 1002 487-3279
- POJ 1002 487-3279(快排)
- POJ 1002 487-3279
- poj 1002 487-3279(参考YSQ)
- C++——字符串例题——487-3279(POJ1002)
- 【POJ 1002】487-3279
- POJ1002 487-3279
- poj - 1002 - 487-3279
- poj 1002 "487-3279"
- POJ 1002 487-3279