#include <stdio.h> #include <stdlib.h> int char2int[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; typedef struct _OCCUR { struct _OCCUR *next; int number; int times; } OCCUR; int main(int argc, char **argv) { int n = 0; scanf("%d", &n); char str[100] = {0}; OCCUR *data[10000] = {0}; while (n--) { scanf("%s", str); char *p = str; int index = 0; int sum_index = 0; int sum = 0; while (*p) { if (*p == '-') { p++; continue; } int one = char2int[*p]; if (index++ < 4) { sum_index = 10 * sum_index + one; } else { sum = 10 * sum + one; } p++; } OCCUR *next = data[sum_index]; OCCUR *prev = data[sum_index]; //printf("index %d, sum %d, %p, %p\n", sum_index, sum, next, prev); while (next) { if (next->number == sum) { next->times++; break; } else if (next->number > sum) { OCCUR *newitem = malloc(sizeof(OCCUR)); newitem->next = NULL; newitem->number = sum; newitem->times = 1; if (prev != next) { prev->next = newitem; newitem->next = next; } else { data[sum_index] = newitem; newitem->next = next; } break; } prev = next; next = next->next; } if (!next) { OCCUR *newitem = malloc(sizeof(OCCUR)); newitem->next = NULL; newitem->number = sum; newitem->times = 1; if (!data[sum_index]) { data[sum_index] = newitem; } else { prev->next = newitem; } } } //printf("after scan\n"); int i = 0; int flag = 0; for (i = 0; i < 10000; i++) { OCCUR *next = data[i]; while (next) { if (next->times > 1) { printf("%03d-%d%03d %d\n", i / 10, i % 10, next->number, next->times); flag = 1; } next = next->next; } } if (!flag) { printf("No duplicates.\n"); } return 0; }
1002
最新推荐文章于 2025-02-11 23:05:33 发布