【洛谷p1051】谁拿了最多奖学金

谁拿了最多奖学金【题目链接】

这道题早就想做它啦。

咱也不知道为啥,咱就是看这道题特别顺眼呢qwq;

MY SOLUTION:

其实这道题很简单,开一个结构体记录各项信息,然后根据条件计算出这个人获得的奖学金(也放在结构体里),然后sort一下;

尽管我不知道是不是真的有相同奖学金(✿✿ヽ(°▽°)ノ✿)的人,但是既然他说了,咱就写一下,因此我在结构体里还加了个num记录输入的编号;然后cmp(* ̄︶ ̄);

CODE:

#include<bits/stdc++.h>

using namespace std;

int n,sum;
struct node{
    char name[20];
    int sor,cla,num;
    char g,w;
    int pas;
    int money;
}stu[110];

bool ys(int i){
    if(stu[i].sor<=80) return 0;
    if(stu[i].pas<1) return 0;
    return 1;
}

bool ws(int i){
    if(stu[i].sor<=85) return 0;
    if(stu[i].cla<=80) return 0;
    return 1;
}

bool yx(int i){
    if(stu[i].sor<=90) return 0;
    return 1;
}

bool west(int i){
    if(stu[i].sor<=85) return 0;
    if(stu[i].w=='N') return 0;
    return 1;
}

bool gx(int i){
    if(stu[i].cla<=80) return 0;
    if(stu[i].g=='N') return 0;
    return 1;
}

bool cmp(node x,node y){
    if(x.money==y.money) return x.num<y.num;
    return x.money>y.money;
}

int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        cin>>stu[i].name>>stu[i].sor>>stu[i].cla>>stu[i].g>>stu[i].w>>stu[i].pas;
        stu[i].num=i;
        if(ys(i)) stu[i].money+=8000;
        if(ws(i)) stu[i].money+=4000;
        if(yx(i)) stu[i].money+=2000;
        if(west(i)) stu[i].money+=1000;
        if(gx(i)) stu[i].money+=850;
        sum+=stu[i].money;
    }
    sort(stu+1,stu+n+1,cmp);
    cout<<stu[1].name<<endl<<stu[1].money<<endl<<sum<<endl;
}

猜你喜欢

转载自www.cnblogs.com/zhuier-xquan/p/11016931.html