Time Limit: 2000MS | |
Memory Limit: 65536K |
Total Submissions: 226038 | |
Accepted: 39379 |
Description 數組
Input spa
Output .net
Sample Input 設計
12 4873279 ITS-EASY 888-4567 3-10-10-10 888-GLOP TUT-GLOP 967-11-11 310-GINO F101010 888-1200 -4-8-7-3-2-7-9- 487-3279
Sample Output 3d
310-1010 2 487-3279 4 888-4567 3
Source code
Translator 排序
/*============================================================================= # FileName: phone_number.cpp # Desc: poj_1002 # Author: zhuting # Email: cnjs.zhuting@gmail.com # HomePage: my.oschina.net/u/1053833 # Version: 0.0.1 # CreatTime: 2013-11-25 # LastChange: 2013-11-25 23:30:45 # History: =============================================================================*/ #include <cstdio> #include <cstdlib> #include <cmath> #include <string> #include <cstring> #include <algorithm> #define maxn 100005/*最大字符串個數*/ #define str_maxn 205/*最大字符串長*/ using namespace std; int main() { /* * num爲字母數字映射數組 * n爲字符串個數 * phone爲每一個號碼的整數表示 * str_tmp爲臨時字符串 */ int num[26] = {2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 0, 7, 7, 8, 8, 8, 9, 9, 9, 0}; int n = 0; int phone[maxn] = {0}; char str_tmp[str_maxn]; scanf("%d", &n); for (int i = 0; i < n; ++i) { scanf("%s", str_tmp); int len = strlen(str_tmp); int cur = 7;/*cur爲當前讀入整形的第幾位*/ for (int j = 0; j < len; ++j) { if (str_tmp[j] >= '0' && str_tmp[j] <= '9') { phone[i] += (str_tmp[j] - '0') * ((int)pow(10.0, --cur));/*字符串轉整形*/ if (cur == 0) break; } else if (str_tmp[j] >= 'A' && str_tmp[j] <= 'Z') { phone[i] += num[str_tmp[j] - 'A'] * ((int)pow(10.0, --cur)); if (cur == 0) break; } } } sort(phone, phone + n);/*排序*/ /*for test*/ /*for (int i = 0; i < n; ++i) printf ("%d\n", phone[i]);*/ /* * is_exist記錄是否存在,存在則爲1 * cur_num當前值 * times當前值出現的次數 */ bool is_exist = 0; int cur_num = phone[0]; int times = 1; for (int i = 1; i < n; ++i) { if (phone[i] == cur_num) { ++times; } else { if (times >= 2) { is_exist = 1; int front = cur_num / 10000;/*前3位*/ int back = cur_num % 10000;/*後4位*/ printf ("%03d-%04d %d\n", front, back, times); } times = 1; cur_num = phone[i]; } } if (times >= 2)/*收尾檢查!!!*/ { is_exist = 1; int front = cur_num / 10000; int back = cur_num % 10000; printf ("%03d-%04d %d\n", front, back, times); } if (!is_exist) printf("No duplicates.\n"); return 0; }