#include<stdio.h> #include<string.h> typedef struct ErrRecord { char name[20]; int line; int count; } ErrRecord; int main() { ErrRecord record[100]; int rindex = -1; char str[100]; int line; while (EOF != scanf("%s%d", str, &line)) { int i, j; int len = strlen(str); char name[20]; for (i = len - 1; i >= 0; i--) { if (str[i] == '\\') break; } //从i+1 下一位开始复制,还有考虑长度不能超过16 if (i + 1 < len - 16) { strcpy(name, str + len - 16); } else { strcpy(name, str + i + 1); } int flag = 0; //标志能否在前面发现相同的记录 1:发现,0:未发现。 for (i = 0; i <= rindex; i++) { if ( (0 == strcmp(name, record[i].name)) && (line == record[i].line) ) { record[i].count++; flag = 1; break; } } if (0 == flag) { ++rindex; strcpy(record[rindex].name, name); record[rindex].line = line; record[rindex].count = 1; } } int temp_buff[rindex + 1]; int temp; int j, k; for (j = 0; j <= rindex; j++) { temp_buff[j] = record[j].count; } //冒泡排序 for (j = 0; j <= rindex; j++ ) { for (k = 0 ; k <= rindex - j - 1; k++) { if (record[k].count < record[k + 1].count) { temp = record[k + 1].count; record[k + 1].count = record[k].count; record[k].count = temp; } } } //最多只输出8条 for (j = 0; j <= 7; j++) { for (k = 0 ; k <= rindex; k++) { if (record[j].count == temp_buff[k]) { printf("%s %d %d\n", record[k].name, record[k].line, temp_buff[k]); temp_buff[k] = 0; break; } } } return 0; }