杭电ACM2061:这道题我是用结构体来做的,但是提交上去就是WA 或是 运行错误,麻烦各位大牛帮我看看!
麻烦不要改我的思路!谢谢!#include<stdio.h>#include<string.h>voidmain(){structGPA{charname;doublec...
麻烦不要改我的思路!谢谢!
#include <stdio.h>
#include <string.h>
void main()
{
struct GPA
{
char name;
double credit,score;
};
struct GPA gpa[30];
int n,m,i,j,count;
double s,s1,s2;
scanf("%d",&n);
getchar();
if(n==1)
{
s1=s2=0;
count=0;
scanf("%d",&m);
for(j=1;j<=m;j++)
{
scanf("%s%lf%lf",&gpa[j].name,&gpa[j].credit,&gpa[j].score);
}
for(j=1;j<=m;j++)
{
if((gpa[j].score<60)&&(gpa[j].score>=0))
count=count+1;
}
if(count>0)
{
printf("Sorry!\n");
}
if(count==0)
{
for(j=1;j<=m;j++)
{
s1=gpa[j].credit*gpa[j].score+s1;
s2=gpa[j].credit+s2;
}
s=1.0*s1/s2;
printf("%.2lf\n",s);
}
}
if(n!=1)
{
for(i=1;i<n;i++)
{
s1=s2=0;
count=0;
scanf("%d",&m);
for(j=1;j<=m;j++)
{
scanf("%s%lf%lf",&gpa[j].name,&gpa[j].credit,&gpa[j].score);
}
for(j=1;j<=m;j++)
{
if((gpa[j].score<60)&&(gpa[j].score>=0))
count=count+1;
}
if(count>0)
{
printf("Sorry!\n");
printf("\n");
}
if(count==0)
{
for(j=1;j<=m;j++)
{
s1=gpa[j].credit*gpa[j].score+s1;
s2=gpa[j].credit+s2;
}
s=1.0*s1/s2;
printf("%.2lf\n",s);
printf("\n");
}
}
s1=s2=0;
count=0;
scanf("%d",&m);
getchar();
for(j=1;j<=m;j++)
{
scanf("%s%lf%lf",&gpa[j].name,&gpa[j].credit,&gpa[j].score);
}
for(j=1;j<=m;j++)
{
if((gpa[j].score<60)&&(gpa[j].score>=0))
count=count+1;
}
if(count>0)
{
printf("Sorry!\n");
}
if(count==0)
{
for(j=1;j<=m;j++)
{
s1=gpa[j].credit*gpa[j].score+s1;
s2=gpa[j].credit+s2;
}
s=1.0*s1/s2;
printf("%.2lf\n",s);
}
}
} 展开
#include <stdio.h>
#include <string.h>
void main()
{
struct GPA
{
char name;
double credit,score;
};
struct GPA gpa[30];
int n,m,i,j,count;
double s,s1,s2;
scanf("%d",&n);
getchar();
if(n==1)
{
s1=s2=0;
count=0;
scanf("%d",&m);
for(j=1;j<=m;j++)
{
scanf("%s%lf%lf",&gpa[j].name,&gpa[j].credit,&gpa[j].score);
}
for(j=1;j<=m;j++)
{
if((gpa[j].score<60)&&(gpa[j].score>=0))
count=count+1;
}
if(count>0)
{
printf("Sorry!\n");
}
if(count==0)
{
for(j=1;j<=m;j++)
{
s1=gpa[j].credit*gpa[j].score+s1;
s2=gpa[j].credit+s2;
}
s=1.0*s1/s2;
printf("%.2lf\n",s);
}
}
if(n!=1)
{
for(i=1;i<n;i++)
{
s1=s2=0;
count=0;
scanf("%d",&m);
for(j=1;j<=m;j++)
{
scanf("%s%lf%lf",&gpa[j].name,&gpa[j].credit,&gpa[j].score);
}
for(j=1;j<=m;j++)
{
if((gpa[j].score<60)&&(gpa[j].score>=0))
count=count+1;
}
if(count>0)
{
printf("Sorry!\n");
printf("\n");
}
if(count==0)
{
for(j=1;j<=m;j++)
{
s1=gpa[j].credit*gpa[j].score+s1;
s2=gpa[j].credit+s2;
}
s=1.0*s1/s2;
printf("%.2lf\n",s);
printf("\n");
}
}
s1=s2=0;
count=0;
scanf("%d",&m);
getchar();
for(j=1;j<=m;j++)
{
scanf("%s%lf%lf",&gpa[j].name,&gpa[j].credit,&gpa[j].score);
}
for(j=1;j<=m;j++)
{
if((gpa[j].score<60)&&(gpa[j].score>=0))
count=count+1;
}
if(count>0)
{
printf("Sorry!\n");
}
if(count==0)
{
for(j=1;j<=m;j++)
{
s1=gpa[j].credit*gpa[j].score+s1;
s2=gpa[j].credit+s2;
}
s=1.0*s1/s2;
printf("%.2lf\n",s);
}
}
} 展开
1个回答
展开全部
相信我没有修改你的思路
你的结构就是太混乱了而已
#include <stdio.h>
#include <string.h>
void main()
{
char name[31]; // 字符串
double credit,score;
int n,m,i,j,count;
double s,s1,s2;
scanf("%d",&n);
while(n--)
{
s1=s2=0;
count=0;
scanf("%d",&m);
for(j=1;j<=m;j++)
{
scanf("%s%lf%lf",name,&credit,&score);
s1=credit*score+s1;
s2=credit+s2;
if(score<60) count=1;
}
if(count>0)
{
printf("Sorry!\n");
}
if(count==0)
{
s=1.0*s1/s2;
printf("%.2lf\n",s);
}
if(n) putchar(10);
}
}
你的结构就是太混乱了而已
#include <stdio.h>
#include <string.h>
void main()
{
char name[31]; // 字符串
double credit,score;
int n,m,i,j,count;
double s,s1,s2;
scanf("%d",&n);
while(n--)
{
s1=s2=0;
count=0;
scanf("%d",&m);
for(j=1;j<=m;j++)
{
scanf("%s%lf%lf",name,&credit,&score);
s1=credit*score+s1;
s2=credit+s2;
if(score<60) count=1;
}
if(count>0)
{
printf("Sorry!\n");
}
if(count==0)
{
s=1.0*s1/s2;
printf("%.2lf\n",s);
}
if(n) putchar(10);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询