UVa 755 - 487--3279
2010-02-28 19:07
495 查看
/* coder: ACboy date: 2010-2-28 result: 1AC description: UVa 755 - 487--3279 */ #include <iostream> #include <string> #include <algorithm> using namespace std; const int MAXN = 100010; char one[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; char two[] = "2223334445556667N77888999N"; string tel[MAXN]; int cmp(const void * a, const void * b) { return strcmp((char *)a, (char *)b) > 0; } char binarySearch(char findChar) { int begin = 0; int end = strlen(one); int mid; while (begin <= end) { mid = (begin + end) / 2; if (one[mid] == findChar) return two[mid]; else if (one[mid] > findChar) { end = mid - 1; } else { begin = mid + 1; } } return 'N'; } void fun(string & to, char from[]) { int i; int fromlen = strlen(from); int c = 0; for (int i = 0; i < fromlen; i++) { if (c == 3) { to = to + "-"; i--; c++; } else { if (isalpha(from[i]) && from[i] != 'Q' && from[i] != 'Z') { to.append(1, binarySearch(from[i])); c++; } else if (isdigit(from[i])){ to.append(1, from[i]); c++; } } } if (c < 3) { for (i = c; i <= 2; i++) { to = to + "0"; } to += "-"; for (i = 1; i <= 4; i++) { to = to + "0"; } } else if (c == 3){ for (i = 1; i <= 4; i++) { to = to + "0"; } } else if (c > 3 && c < 8) { for (i = 1; i <= 7 - c; i++) { to = to + "0"; } } } int main() { int i, j; int n; #ifndef ONLINE_JUDGE freopen("755.txt", "r", stdin); #endif scanf("%d", &n); while (n--) { int count; scanf("%d/n", &count); for (i = 0; i < count; i++) { tel[i].clear(); tel[i].reserve(20); char temp[20]; gets(temp); fun(tel[i], temp); } sort(tel, tel + count); int flag = 0; string current = tel[0]; int num = 1; for (j = 1; j < count; j++) { if (current == tel[j]) num++; else { if (num >= 2) { cout << tel[j - 1] << " " << num << endl; num = 1; current = tel[j]; flag = 1; } else { current = tel[j]; num = 1; } } if (j == count - 1 && num >= 2) { cout << tel[j] << " " << num << endl; flag = 1; } } if (!flag) { cout << "No duplicates." << endl; } if (n > 0) printf("/n"); } return 0; }
相关文章推荐
- UVa 755 / POJ 1002 - 487-3279
- UVa 755 / POJ 1002 / East Central North America 1999 487--3279 (排序)
- uva 755 (487--3279)排序
- uva 755 487--3279(字母与数字处理)
- uva 755/poj 1002 487-3279
- UVa:755 - 487--3279
- UVa755 487-3279
- UVa: 755 - 487--3279
- UVa 755 487--3279
- UVa 755 - 487--3279
- uva 755 487--3279(检索+排序)
- UVA 755 - 487--3279
- uva 755 487--3279
- Uva 755 - 487--3279
- Uva 755 487--3279
- UVa 755 - 487--3279
- UVA - 755 487--3279 sort的使用
- UVA 755-487--3279
- 开篇,UVA 755 && POJ 1002 487--3279 (Trie + DFS / sort)
- uva 755 - 487--3279