易懂c++代码
2025-07-16 22:01:33
发布于:上海
9阅读
0回复
0点赞
这道题运用结构体存储学员数据,按要求计算各自奖学金,并输出要求的数据
写时有点费脑子
代码如下(最朴实易懂的写法):
#include<iostream>
#include<algorithm>
using namespace std;
int n, sum;
struct people{
string name;
int cas;
int cs;
char st, west;
int w, j, mo;
}a[101];
bool cmp(people a, people b){
if(a.j == b.j){
return a.mo < b.mo;
}
return a.j > b.j;
}
int main(){
cin >> n;
for(int i = 0; i < n; i++){
cin >> a[i].name >> a[i].cas >> a[i].cs >> a[i].st >> a[i].west >> a[i].w;
a[i].mo = i;
if(a[i].cas > 80 && a[i].w >= 1){
a[i].j += 8000;
}
if(a[i].cas > 85 && a[i].cs > 80){
a[i].j += 4000;
}
if(a[i].cas > 90){
a[i].j += 2000;
}
if(a[i].cas > 85 && a[i].west == 'Y'){
a[i].j += 1000;
}
if(a[i].cs > 80 && a[i].st == 'Y'){
a[i].j += 850;
}
sum += a[i].j;
}
sort(a, a + n, cmp);
cout << a[0].name << endl;
cout << a[0].j << endl;
cout << sum;
return 0;
}
全部评论 2
认为写的可以的记得加入本人学习交流团:https://www.acgo.cn/application/1942517586006433792
2025-07-16 来自 上海
1制作不易,留赞后去
2025-07-16 来自 上海
1
有帮助,赞一个