CodingNoStop 2021-04-22 23:29 采纳率: 40%
浏览 329
已采纳

大佬们,能帮我看看这个代码哪里出问题了吗,晕了呀

#include <stdio.h>
#include <string.h>

int main()
{
    int std_num,thg_num,temp;
    int std_fid=0,thg_fid=0;
    int thg_all[10000];
    char*name[5];
    
    scanf("%d %d",&std_num,&thg_num);
    for(int i=0;i<thg_num;i++){
        scanf("%d",&temp); 
        thg_all[temp]++;}
    
    for(int i=0;i<std_num;i++){
        scanf("%s ",name);
        
        int thg_haf,fir=1;
        scanf("%d",&thg_haf);
        for(int p=0;p<thg_haf;p++){
            scanf("%d",&temp);
            if (thg_all[temp]==1){
                thg_fid++;
                if (fir) {
                    printf("%s: ",name); 
                    printf("%04d",temp); 
                    fir=0; std_fid++;}
                else 
                      printf(" %04d",temp);}
            if (!fir&&p==thg_haf-1) 
                        printf("\n");
        }}printf("%d %d",std_fid,thg_fid); 
          return 0;
}

这是一道PAT的练习题,我测试点3怎么都过不去...但是在网上搜,也没人出这个问题....有没有大佬帮我瞅瞅。原题链接在这里https://pintia.cn/problem-sets/994805260223102976/problems/994805263964422144

  • 写回答

2条回答 默认 最新

  • 兔老大RabbitMQ Java领域优质创作者 2021-04-23 00:42
    关注
    #include <stdio.h>
    #include <string.h>
    int main()
    {
        int std_num,thg_num,temp;
        int std_fid=0,thg_fid=0;
        int thg_all[10000]={0};
        char*name[5];
        scanf("%d %d",&std_num,&thg_num);
        for(int i=0;i<thg_num;i++){
            scanf("%d",&temp); 
            thg_all[temp]++;
        }
        for(int i=0;i<std_num;i++)
        {
            scanf("%s ",name);
            int thg_haf,fir=1;
            scanf("%d",&thg_haf);
            for(int p=0;p<thg_haf;p++)
            {
                scanf("%d",&temp);
                if (thg_all[temp]==1)
                {
                    thg_fid++;
                    if (fir) 
                    {
                        printf("%s: %04d",name,temp); 
                        fir=0; std_fid++;
                    }
                    else 
                    {
                        printf(" %04d",temp);
                    }
                }
                if ((!fir) && (p==thg_haf-1))printf("\n");
            }
        }
        printf("%d %d\n",std_fid,thg_fid); 
        return 0;
    }

    改了下格式,写的实在没法看。

    ac了,应该就是初始化的锅,另外没必要这么做。

    觉得可以采纳一下

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b