小白求助!输出和答案完全相同却判错!

全部评论
以下是我提交的源代码(题目是华为2016校园招聘上机笔试题第二题) #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <stdlib.h> #include <string.h> #define MAX_CNT 8 typedef struct {     char file_name[20];     int rank;          //记录出现的顺序     int cnt; }ERROR_FILE; ERROR_FILE error_file[10]; //这里不定义数组的数量会有问题么? void Swap(ERROR_FILE *a, ERROR_FILE *b) {     ERROR_FILE temp = *a;     *a = *b;     *b = temp; } void delete_repeat(char *temp,int *index) {     int i,flag = 0;     for(i = 0;i < (*index);i++)     {         if(strcmp(temp,error_file[i].file_name) == 0)         {             error_file[i].cnt++;             flag = 1;             break;         }             }     if(flag == 0)     {         strcpy(error_file[*index].file_name,temp);         error_file[*index].cnt++;         error_file[*index].rank = *index;         (*index)++;     } } void sort_error_file(int num) {     int i,j;     for(i = 0;i < num;i++)     {         for(j = 1;j < num - i;j++)         {             if(error_file[j - 1].cnt < error_file[j].cnt)             {                 Swap(&error_file[j - 1],&error_file[j]);             }             else if(error_file[j - 1].cnt == error_file[j].cnt)             {                 if(error_file[j - 1].rank > error_file[j].rank)                 {                     Swap(&error_file[j - 1],&error_file[j]);                     }             }         }     } } int main() {     int len,i,j,x,num = 0;     char* s = (char *)malloc(sizeof(char));     char* temp_reslut = (char *)malloc(sizeof(char));     while(gets(s))     {         len = strlen(s);         if(len <= 0)             break;         i = len - 1;         while(s[i] != 92) //反斜杠对应的ascii码             i--;         strcpy(temp_reslut,&s[i+1]);          delete_repeat(temp_reslut,&num);     }     sort_error_file(num);     x = num > MAX_CNT ? MAX_CNT : num;     for(j = 0;j < x;j++)     {         if(j < x - 1)         {             printf("%s %d ",error_file[j].file_name,error_file[j].cnt);         }         else          {             printf("%s %d",error_file[j].file_name,error_file[j].cnt);         }     }     return 0; }
点赞 回复
分享
发布于 2018-10-23 09:41
求大佬帮忙看下~
点赞 回复
分享
发布于 2018-10-22 18:01
博乐游戏
校招火热招聘中
官网直投
额,是不是结尾的空格没有去掉
点赞 回复
分享
发布于 2018-10-22 18:06
加个换行?
点赞 回复
分享
发布于 2018-10-22 18:48
你应该让他多次输入,while()。这样去试试
点赞 回复
分享
发布于 2018-10-22 18:52

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务