题解 | #简单错误记录#

简单错误记录

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;
}

全部评论

相关推荐

10-24 11:10
山西大学 Java
若梦难了:哥们,面试挂是很正常的。我大中厂终面挂,加起来快10次了,继续努力吧。
点赞 评论 收藏
分享
11-09 12:17
清华大学 C++
out11Man:小丑罢了,不用理会
点赞 评论 收藏
分享
评论
1
收藏
分享
牛客网
牛客企业服务