Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
计数排序+哈希处理+printf的0参数简单字符串处理与排序。数据规模比较大,一般的排序很可能超时。这里采用空间换时间的计数排序,字母数字转换采用哈希表,输出的时候注意printf中0参数的用意。 C++源码 #include <stdio.h> const int N = 10000000; unsigned int times[N]; int main() { int num; // talbe[]="ABCDEFGHIGKLMNOPQRSTUVWXYZ" char table[]="22233344455566670778889990", s[128]; scanf("%d", &num); for(int i=0;i<num;i++){ scanf("%s", s); int sum = 0; for(int j=0;s[j]!='\0';j++){ if(s[j]>='A' && s[j]<='Z') sum = sum*10 + table[(int)(s[j]-'A')]-'0'; else if(s[j]>='0' && s[j]<='9') sum = sum*10 + s[j]-'0'; } times[sum]++; } int f=0; for(int i=0;i<N;i++){ if(times[i]>=2){ f=1; printf("%03d-%04d %d\n", i/10000,i%10000,times[i]); } } if(f==0) printf("No duplicates.\n"); return 0; } 转自:http://blog.csdn.net/koala002/archive/2011/05/17/6426325.aspx Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator