POJ1002-纯净水题,注意题目要求
来源:互联网 发布:一键岚之山 软件 编辑:程序博客网 时间:2024/04/27 15:58
#include <cstdio>#include <cstdlib>#include <iostream>#include <cstring>#include <vector>#include <queue>#include <cctype>using namespace std;int n;char s[50];int hash[10000000]; //一对一的hash表,10000000勉强能过,也可开个n大的表再排序;int transform(char c){ if (isdigit(c)) return c-'0'; if (c<='C') return 2; if (c<='F') return 3; if (c<='I') return 4; if (c<='L') return 5; if (c<='O') return 6; if (c<='S') return 7; if (c<='V') return 8; if (c<='Y') return 9;}void chuli(char s[]){ int x=0,k=0; for (int i=0; s[i] && k<7; i++) if (isalpha(s[i]) || isdigit(s[i]) && s[i]!='Q' && s[i]!='Z') { k++; int y=transform(s[i]); x=x*10+y; } hash[x]++;}int main(){ scanf("%d",&n); getchar(); for (int i=0; i<10000000; i++) hash[i]=0; for (int i=1; i<=n; i++) { gets(s); chuli(s); } bool mark=false; for (int i=0; i<10000000; i++) { if (hash[i]>1) { printf("%03d-%04d %d\n",i/10000,i%10000,hash[i]); //注意格式,如001-0000的情况 mark=true; } } if (!mark) printf("No duplicates.\n"); //别忘了 return 0;}