标签:
> 分析
/*--------------------------------- * 使用电话号码全集 * --------------------------------*/ #include "stdio.h" #include "string.h" #include "stdlib.h" /* 字母到数字的映射表 */ const int map[26] = { 2, 2, 2, /* A, B, C */ 3, 3, 3, /* D, E, F */ 4, 4, 4, /* G, H, I */ 5, 5, 5, /* J, K, L */ 6, 6, 6, /* M, N, O */ 7, 0, 7, 7, /* P, Q, R, S */ 8, 8, 8, /* T, U, V */ 9, 9, 9, /* W, X, Y */ 0 /* Z */ } ; /* 电话号码全集 */ int teleNum[10000000] = {0} ; int main(void) { int n = 0 ; char s[50] = {0} ; int num = 0 ; int i = 0 ; int min = 10000000 ; int max = -1 ; scanf("%d", &n) ; while(n--) { memset(s, 0, sizeof(s)) ; scanf("%s", s) ; /* 将电话号码转换为整型 */ num = 0 ; for(i = 0; i < sizeof(s); i++) { if(0 == s[i]) break ; if(‘Q‘ == s[i] || ‘Z‘ == s[i]) continue ; if(s[i] >= ‘A‘ && s[i] <= ‘Z‘) num = num * 10 + map[s[i] - ‘A‘] ; if(s[i] >= ‘0‘ && s[i] <= ‘9‘) num = num * 10 + s[i] - ‘0‘ ; } teleNum[num]++ ; if(2 == teleNum[num]) { min = num < min ? num : min ; max = num > max ? num : max ; } } if(-1 == max) { printf("No duplicates.\r\n") ; return 0 ; } for(i = min; i <= max; i++) { if(teleNum[i] < 2) continue ; printf("%03d-%04d %d\r\n", i / 10000, i % 10000, teleNum[i]) ; } return 0 ; }
标签:
原文地址:http://www.cnblogs.com/codesworld/p/4695289.html