参考别人的代码
简单错误记录
http://www.nowcoder.com/questionTerminal/2baa6aba39214d6ea91a2e03dff3fbeb
#include<stdio.h> #include<string.h> struct list{ char name[200]; int number; int times; }; int main(void){ char cin[200]; int num, head = 0; struct list lists[100]={{{0}, 0, 0}, {{0}, 0, 0}, {{0}, 0, 0}, {{0}, 0, 0}, {{0}, 0, 0}, {{0}, 0, 0}, {{0}, 0, 0}, {{0}, 0, 0}}; while(scanf("%s %d", &cin, &num)!=EOF){ char *p = strrchr(cin, '\\'); int i, len = strlen(++p); p = len > 16 ? p + len - 16 : p; for(i=0; i<head; i++) if(strcmp(lists[i].name, p)==0 && num==lists[i].number) break; if(i==head){ strcpy(&lists[head].name, p); lists[head].times = 1; lists[head].number = num; head += 1; }else lists[i].times += 1; } int count = head - 8>0 ? head - 8 : 0; for(int i=count; i<head; i++) printf("%s %d %d\n", lists[i].name, lists[i].number, lists[i].times); return 0; }