NOIp2005谁拿了最多的奖学金(提高组T1)————字符串,排序

题解:本题主要考查字符串,排序。字符串处理可用string数组,排序不断刷新最大值。
代码如下:

#include <iostream>
#include <string>
using namespace std;
int main()
{
    string name[101],maxstudent;            
    int qimo[101],banji[101];    
    char xuesheng[101],xibu[101];
    int lunwen[101],n,ans=0,money,max1=-1;                 
    cin>>n;
    for(int i=1;i<=n;i++)   
    {
        money=0;       
        cin>>name[i]>>qimo[i]>>banji[i]>>xuesheng[i]>>xibu[i]>>lunwen[i];       
        if(qimo[i]>80&&lunwen[i]>=1) money+=8000;
        if(qimo[i]>85&&banji[i]>80) money+=4000;
        if(qimo[i]>90)money+=2000;
        if(qimo[i]>85&&xibu[i]=='Y') money+=1000;
        if(banji[i]>80&&xuesheng[i]=='Y') money+=850;
        ans+=money;    
        if(money>max1) 
        {
            max1=money;
            maxstudent=name[i];
        }
    }
    cout<<maxstudent<<endl<<max1<<endl<<ans;
    return 0;    
}

猜你喜欢

转载自blog.csdn.net/wly1127/article/details/82432051