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 |
WA9次了,好坑啊,一定要注意Q和Z要和“-”一样过滤掉!!(比较常规的代码,内存900,时间700)#include <iostream> #include <string> #include <vector> #include <algorithm> using namespace std; inline int translate(char before_tran) { switch (before_tran) { case 'A':case 'B':case 'C': return 2; case 'D':case 'E':case 'F': return 3; case 'G':case 'H':case 'I': return 4; case 'J':case 'K':case 'L': return 5; case 'M':case 'N':case 'O': return 6; case 'P':case 'R':case 'S': return 7; case 'T':case 'U':case 'V': return 8; case 'W':case 'X':case 'Y': return 9; default:break; } } int main() { int num, judge = 0; int target[7]; vector<unsigned int> num_int; cin >> num; for (int i = 0; i < num; i++) { string number; int num_tran[7]; int num_tran_index = 0; cin>>number; for (int j = 0; number[j] != '\0'; j++) { if (number[j] <= '9' && number[j] >= '0') { num_tran[num_tran_index] = number[j] - '0'; num_tran_index++; } else if (number[j] == '-' || number[j] == 'Q' || number[j] == 'Z') { continue; } else { num_tran[num_tran_index] = translate(number[j]); num_tran_index++; } } num_int.push_back(num_tran[0] * 1000000 + num_tran[1] * 100000 + num_tran[2] * 10000 + num_tran[3] * 1000 + num_tran[4] * 100 + num_tran[5] * 10 + num_tran[6]); } sort(num_int.begin(), num_int.end()); int count = 0; for (int i = 0, j = 1;j < num;) { if (num_int[i] == num_int[j]) { j++; if (j == num) { count = j - i; printf("%03d-%04d %d\n", num_int[i] / 10000, num_int[i] % 10000, count); } } else { count = j - i; if (count == 1) { i++; j++; judge++; } else { printf("%03d-%04d %d\n", num_int[i] / 10000, num_int[i] % 10000, count); i = j; j++; } } } if (judge == num - 1) { cout << "No duplicates." << endl; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator