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 |
话说这代码好慢啊……#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <map> #include <string> #define foreach(it,v) for (__typeof((v).begin()) it = (v).begin();it != (v).end();++it) using namespace std; map<int,int> mym; char s[1000]; char cc[180]; void init() { for(int i='0'; i<='9'; i++) cc[i] = i - '0'; for(int i='A'; i<='P'; i++) cc[i] = (i - 'A') / 3 + 2; for(int i='R'; i<='Y'; i++) cc[i] = (i - 'B') / 3 + 2; } void gao(char *s) { int tmp = 0; for(int i=0; s[i]; ++i) if(s[i] != '-') tmp = tmp*10+cc[s[i]]; if(mym.find(tmp) == mym.end()) mym[tmp] = 1; else ++ mym[tmp]; } int main() { init(); int n; scanf("%d", &n); mym.clear(); for(int i=0; i<n; i++) { scanf("%s", s); gao(s); } bool have = false; foreach(it, mym) { if(it->second > 1) { have = true; printf("%03d-%04d %d\n",it->first/10000, it->first%10000, it->second); } } if(!have) puts("No duplicates."); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator