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 |
求高人指教,在VC中测试正确呀,为啥老是WA呢?#include <cstdio> #include <map> #include <iterator> using namespace std; const int dic[26]= { 2,2,2,//ABC 3,3,3,//DEF 4,4,4,//GHI 5,5,5,//JKL 6,6,6,//MNO 7,//P -1,//Q 7,7,//RS 8,8,8,//TUV 9,9,9,//WXY -1//Z }; bool getAndTransToSdd(char des[]) { char src[20]; if (scanf("%s",src)) { memset(des,'\0',strlen(des)); int len = strlen(src); int desCur=0; for (int i = 0;i<len;i++) { if (src[i]>='0' && src[i]<='9') { des[desCur]=src[i]; desCur++; } else if (src[i]>='A' && src[i]<='Z') { des[desCur]='0'+dic[src[i]-'A']; desCur++; } else if (src[i]>='a' && src[i]<='z') { des[desCur]='0'+dic[src[i]-'a']; desCur++; } } return true; } else { return false; } } int main() { map<int,int>mem; int n,i; char des[10]={'\0'}; bool someRepeat=false; scanf("%d",&n); for (i=0;i<n;i++) { getAndTransToSdd(des); mem[atoi(des)]++; } for (map<int,int>::iterator it=mem.begin();it!=mem.end();it++) { if (it->second>1) { someRepeat=true; printf("%03d-%04d %d\n",it->first/10000,it->first%10000,it->second); } } if (!someRepeat) { printf("No duplicates.\n"); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator