| ||||||||||
| 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 | |||||||||
Problem 1002code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int cmp(const void *a, const void *b) {
return (*(int *)a - *(int *)b);
}
int get_num(char c) {
if (c >= '0' && c <= '9') return c - '0';
if (c >= 'A' && c <= 'C') return 2;
if (c >= 'D' && c <= 'F') return 3;
if (c >= 'G' && c <= 'I') return 4;
if (c >= 'J' && c <= 'L') return 5;
if (c >= 'M' && c <= 'O') return 6;
if (c >= 'P' && c <= 'S') return 7;
if (c >= 'T' && c <= 'V') return 8;
if (c >= 'W' && c <= 'Y') return 9;
return -1;
}
int main() {
int n;
char s[500];
int arr[100005];
int i, j;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%s", s);
int num = 0;
for (j = 0; s[j]; j++) {
int t = get_num(s[j]);
if (t == -1) continue;
num = num * 10 + t;
}
arr[i] = num;
}
qsort(arr, n, sizeof(int), cmp);
int flag = 0;
int cnt = 1;
for (i = 1; i < n; i++) {
if (arr[i] == arr[i - 1]) {
cnt++;
} else {
if (cnt > 1) {
printf("%03d-%04d %d\n", arr[i - 1] / 10000, arr[i - 1] % 10000, cnt);
flag = 1;
}
cnt = 1;
}
}
if (cnt > 1) {
printf("%03d-%04d %d\n", arr[n - 1] / 10000, arr[n - 1] % 10000, cnt);
flag = 1;
}
if (!flag) {
printf("No duplicates.\n");
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator