大佬们,能帮我看看这个代码哪里出问题了吗,晕了呀
问题描述:
#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
答
#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了,应该就是初始化的锅,另外没必要这么做。
觉得可以采纳一下
答
C和C++完整教程:https://blog.csdn.net/it_xiangqiang/category_10581430.html
C和C++算法完整教程:https://blog.csdn.net/it_xiangqiang/category_10768339.html