一开始想着用结构体方便,确实很方便而且也很整洁,但是最后在寻找最大值时没有用到strcpy(h,f); //h[20]为获得最高奖学金的学生姓名;导致最后超时并且运行出错,很多时候逻辑上想是没有错,但运行时总会出错。证明一个道理,,,在没有逼格之前就谦虚学习别人也是好事。
#include <stdio.h>
#include <stdlib.h>
struct Stduent{
char name;
int final_mark;
int avange_mark;
int thesis;
char west;
char leader;
int s;
}test;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
int s,n,schoolar;
scanf("%d",&s);
while(s--){
scanf("%d",&n);
int a[n],i;
char b[n];
schoolar=0;
while(n--){
scanf("%s%d%d%c%c%d",&test.name,&test.avange_mark,&test.final_mark,&test.leader,&test.west,&test.thesis);
if(test.avange_mark>80&&test.thesis>1)
test.s+=8000;
if(test.avange_mark>85&&test.final_mark>80)
test.s+=4000;
if(test.avange_mark>90)
test.s+=2000;
if(test.avange_mark>85&&test.west=='Y')
test.s+=1000;
if(test.final_mark>80&&test.leader=='Y')
test.s+=850;
a[n]=test.s;
b[n]=test.name;
}
int max=a[0];
for(i=1;i<n;i++){
if(a[i]>=max)
max=a[i];}
for(i=0;i<n;i++){
if(max==a[i])
printf("%s\n",b[i]);
}
printf("%d\n",max);
for(i=0;i<n;i++)
schoolar+=a[i];}
return 0;
}
#include <stdio.h>
#include <string.h>
int main()
{
int n,m,i,s1,s,a,b,e,max;
char f[20],h[20],c,d;
scanf("%d",&n); //测试数据的组数
while(n--)
{
s1=0; //s1 为个人奖学金总数
s=0; //s 为奖学金总数
scanf("%d",&m); //每组的学生总数
scanf("%s %d %d %c %c %d",f,&a,&b,&c,&d,&e);
if(a>80 && e>=1) s1+=8000;
if(a>85 && b>80) s1+=4000;
if(a>90) s1+=2000;
if(a>85 && d=='Y') s1+=1000;
if(b>80 && c=='Y') s1+=850;
s+=s1;
max=s1; //max为最高奖学金
strcpy(h,f); //h[20]为获得最高奖学金的学生姓名
while(--m)
{
scanf("%s %d %d %c %c %d",f,&a,&b,&c,&d,&e);
s1=0;
if(a>80 && e>=1) s1+=8000;
if(a>85 && b>80) s1+=4000;
if(a>90) s1+=2000;
if(a>85 && d=='Y') s1+=1000;
if(b>80 && c=='Y') s1+=850;
if(s1>max) //如果有更高的奖学金
{
strcpy(h,f); //更换姓名
max=s1; //更换最高奖学金
}
s+=s1;
}
printf("%s\n%d\n%d\n",h,max,s);
}
return 0;
}
---------------------
作者:ljyanjy
来源:CSDN
原文:https://blog.csdn.net/LVJINYANJY/article/details/77821930