分析:本题意在测试字符串、字符、与数字同时出现如何读入

另外由于题目要求输出获得奖学金最多学生的姓名,猛地一看好像需要保存数据。其实只定义一个变量保存做多奖学金的学生姓名即可。

边读入边处理,但是保存了所有数据的程序:

#include<cstdio>
char name[110][30];
int qm[110],py[110],num[110];
char gb[110],xb[110];
int main(){
    int n,maxs=0,t=0,s=0;
    char x;
    scanf("%d",&n);
    for (int i=1;i<=n;i++){
        scanf("%s",name[i]);
        scanf("%d%d",&qm[i],&py[i]);
        scanf("%c%c%c%c",&x,&gb[i],&x,&xb[i]);
        scanf("%d",&num[i]);
        //            scanf("%s%d%d%c%c%d",name[i],&qm[i],&py[i],gb[i],xb[i],&num[i]);
        int sum=0;
        if (qm[i]>80&&num[i]>0) sum=sum+8000;
        if (qm[i]>85&&py[i]>80) sum=sum+4000;
        if (qm[i]>90)        sum=sum+2000;
        if (qm[i]>85&&xb[i]=='Y')sum=sum+1000;
        if (py[i]>80&&gb[i]=='Y')sum=sum+850;
        if (sum>maxs) {
            maxs=sum;
            t=i;
        }
        s=s+sum;    
    }
    printf("%s\n%d\n%d\n",name[t],maxs,s);
    return 0;
}
View Code

边读入边处理,只保存了必须数据的程序:

//不用数组 ,最优质对应的name用sname保存 
#include<cstdio>
#include<cstring>
char name[30],sname[30];
int main(){
    int n,maxs=0,t=0,s=0,qm,py,num;
    char x,gb,xb;
    scanf("%d",&n);
    for (int i=1;i<=n;i++){
        scanf("%s",name);
        scanf("%d%d",&qm,&py);
        scanf("%c%c%c%c",&x,&gb,&x,&xb);//空格也是字符 
        scanf("%d",&num);
        int sum=0;
        if (qm>80&&num>0) sum+=8000;
        if (qm>85&&py>80) sum+=4000;
        if (qm>90)        sum+=2000;
        if (qm>85&&xb=='Y')sum+=1000;
        if (py>80&&gb=='Y')sum+=850;
        if (sum>maxs) {
            maxs=sum;
            t=i;
            strcpy(sname,name);//char类型的字符数组不能直接赋值 
        }
        s=s+sum;    
    }
    printf("%s\n%d\n%d\n",sname,maxs,s);
    return 0;
}
View Code

上述程序为了避免出错,我分类进行了读入。

scanf("%s",name);
scanf("%d%d",&qm,&py);
scanf("%c%c%c%c",&x,&gb,&x,&xb);//空格也是字符
scanf("%d",&num);

其实可以简化为:

scanf("%s%d%d%s%s%d",name,&qm,&py,&gb,&xb,&num);//按字符串读入可以避开空格 
但是:
  定义:char x,gb[10],xb[10];
  判断:

if (qm>85&&xb[0]=='Y')sum+=1000;
if (py>80&&gb[0]=='Y')sum+=850;

//不用数组 ,最优质对应的name用sname保存 
#include<cstdio>
#include<cstring>
char name[30],sname[30];
int main(){
    int n,maxs=0,t=0,s=0,qm,py,num;
    char x,gb[10],xb[10];
    scanf("%d",&n);
    for (int i=1;i<=n;i++){
        scanf("%s%d%d%s%s%d",name,&qm,&py,&gb,&xb,&num);//按字符串读入可以避开空格 
        int sum=0;
        if (qm>80&&num>0) sum+=8000;
        if (qm>85&&py>80) sum+=4000;
        if (qm>90)        sum+=2000;
        if (qm>85&&xb[0]=='Y')sum+=1000;
        if (py>80&&gb[0]=='Y')sum+=850;
        if (sum>maxs) {
            maxs=sum;
            t=i;
            strcpy(sname,name);//char类型的字符数组不能直接赋值 
        }
        s+=sum;    
    }
    printf("%s\n%d\n%d\n",sname,maxs,s);
    return 0;
}
View Code