Last active
December 16, 2015 11:09
-
-
Save yukixz/5425139 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#define MAXLEN 100000 | |
#define NUMLEN 64 | |
int compare(void const *a, void const *b) { | |
return ( *(int*)a -*(int*)b ); | |
} | |
int maps[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 tel[MAXLEN]; | |
char input[NUMLEN]; | |
int main() | |
{ | |
int i, j, num, count, isdup; | |
char ch; | |
// Input | |
scanf("%d", &num); | |
for(i=0; i<num; i++) { | |
scanf("%s", input); | |
j=0; | |
ch=input[j]; | |
tel[i]=0; | |
while(ch!='\0') { | |
if(ch>='0'&&ch<='9') | |
tel[i] = tel[i]*10 + ch-'0'; | |
if(ch>='A'&&ch<='Z') | |
tel[i] = tel[i]*10 + maps[ch-'A']; | |
ch=input[++j]; | |
} | |
} | |
// Process | |
qsort(tel, num, sizeof(int), compare); | |
isdup=0; | |
count=1; | |
for(i=1; i<num; i++) { | |
if(tel[i]==tel[i-1]) | |
count++; | |
else { | |
if(count>1) { | |
printf("%03d-%04d %d\n", tel[i-1]/10000, tel[i-1]%10000, count); | |
isdup=1; | |
} | |
count=1; | |
} | |
} | |
if(count>1) { | |
printf("%03d-%04d %d\n", tel[i-1]/10000, tel[i-1]%10000, count); | |
isdup=1; | |
} | |
if(!isdup) | |
printf("No duplicates.\n"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
写得好复杂...