题解 | #简单错误记录#
简单错误记录
https://www.nowcoder.com/practice/2baa6aba39214d6ea91a2e03dff3fbeb
#include <stdio.h> #include <string.h> typedef struct{ char word[20]; int len; int count; }PRINT_NODE; int outlength = 0; void findAndUpdateErr(char* str,int len, PRINT_NODE* out) { int findFlag = 0; int outLen = 0; for(int i = 0; i < outlength; i++) { if((0 == strcmp(str,out[i].word)) && (out[i].len == len)) { out[i].count++; findFlag = 1; break; } } if(0 == findFlag) { strcpy(out[outlength].word, str); out[outlength].len = len; out[outlength].count = 1; outlength++; } } int main() { char log[100][100] = {0}; char word[100][16] = {0}; int len[100] = {0}; PRINT_NODE out[100] = {0}; char ch = 0; char line[100] = {0}; int i = 0; int LineRec = 0; char filePath[108] = {0}; int index = 0; int tempLen = 0; int position = 0; memset(out,0x00,sizeof(PRINT_NODE)*100); while(EOF != scanf("%s %d",filePath,&LineRec)) { tempLen = strlen(filePath); for(i = 0; i < 16; i++) { ch = filePath[tempLen - i-1]; if('\\' != ch) position++; else{ break; } } len[index] = LineRec; position = i > position ? i : position; strcpy(word[index],filePath + tempLen - position); findAndUpdateErr(word[index],len[index], out); position = 0; memset(filePath,0x00,108); index++; } if(outlength >= 8){ for(int i = 0; i < 8 && i < outlength; i++) { index = outlength - (8-i); printf("%s %d %d\n",out[index].word,out[index].len,out[index].count); } } if(outlength < 8) { for(int i = 0; i < outlength; i++) { index = i;//outlength- 1 - (8-i); printf("%s %d %d\n",out[index].word,out[index].len,out[index].count); } } return 0; }