Super_Je 2017-07-14 07:30 采纳率: 0%
浏览 859

求解PAT1004乙级题用结构体部分通过问题

图片说明
上图为题目,我用了两种方法解答,本质是一样的,为什么用结构体的方法只是部分通过呢,而第一种方法就全部通过了。两种方法已经附上。
#include
int main()
{
__**#if 0
char name[100][100]={0},id[100][100]={0};
int marks[100]={0},num=0,i=0,j=0;
int temp1=0,temp2=0;
int min,max;
scanf("%d",&num);
for(;i {
scanf("%s",&name[i]);
scanf("%s",&id[i]);
scanf("%d",&marks[i]);
}
min=marks[0];
max=marks[0];
for(i=1;i {
if(marks[i] {
min=marks[i];
temp1=i;
}
}
for(j=1;j {
if(marks[j]>max)
{
max=marks[j];
temp2=j;
}
}
printf("%s %s\n",name[temp2],id[temp2]);

printf("%s %s\n",name[temp1],id[temp1]);
#endif__**

typedef struct student{
char name[100][100];
char id[100][100];
int marks[100];
}STU;
int num=0,i=0,j=0;
int temp1=0,temp2=0;
int min,max;
STU stu1;

scanf("%d",&num);
for(;i {
scanf("%s",&stu1.name[i]);
scanf("%s",&stu1.id[i]);
scanf("%d",&stu1.marks[i]);
}
min=stu1.marks[0];
max=stu1.marks[0];
for(i=1;i {
if(stu1.marks[i] {
min=stu1.marks[i];
temp1=i;
}
}
for(j=1;j {
if(stu1.marks[j]>max)
{
max=stu1.marks[j];
temp2=j;
}
}
printf("%s %s\n",stu1.name[temp2],stu1.id[temp2]);

printf("%s %s\n",stu1.name[temp1],stu1.id[temp1]);
return 0;
}

  • 写回答

1条回答 默认 最新

  • threenewbee 2017-07-14 11:26
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料