|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include <bits/stdc++.h>
using namespace std;
struct Student {
char name[20];
int finalscore;
int classscore;
char isworker;
char iswest;
int article;
};
int n;
int maxpay = 0;
char maxstu[20];
int totalpay = 0;
int pay = 0;
int main(){
scanf("%d", &n);
struct Student student[n];
for(int i = 0; i < n; i++){
scnaf("%s%d%d%c%c%d", \
&student[i].name\
&student[i].finalscore\
&student[i].classscore\
&student[i].isworker\
&student[i].iswest\
&student[i].article);
}
for(int i = 0; i < n; i++){
if(student[i].classscore > 80){
if(student[i].article > 0){
pay += 8000; //院士
}
}
if(student[i].finalscore > 85){
if(student[i].classscore > 80){
pay += 4000; //五四
}
if(student[i].iswest == 'Y'){
pay += 1000; //西部
}
}
if(student[i].finalscore > 90){
pay += 2000; //成绩
}
if(student[i].classscore > 80 && student[i].isworker == 'Y'){
pay += 850;
}
if(pay > maxpay){
maxpay = pay;
strcpy(maxstu, student[i].name);
}
totalpay += pay;
}
}
printf("%s\n%d\n%d", maxstu, maxpay, totalpay);
return 0;
}
代码如上 , 题目链接在下
https://www.luogu.com.cn/problem/P1051
求助 , 我写的代码老是报错 , 不知道怎么回事...
另外 , 也不知道这个代码能不能解决问题
#include <iostream>
#include <vector>
#include <utility>
typedef struct Students {
std::string name;
size_t exam, review;
bool leader, western;
short published;
size_t scholarship;
Students(std::string n, size_t e, size_t r, bool l, bool w, short p) :
name(n),
exam(e),
review(r),
leader(l),
western(w),
published(p),
scholarship(0){}
}Students;
int main() {
std::string name;
size_t N, exam, review;
char leader, western;
short published;
std::cin >> N;
std::vector<Students> std;
for (size_t n = 0; n < N; n++) {
std::cin
>> name
>> exam
>> review
>> leader
>> western
>> published;
std.push_back({ name, exam, review, leader == 'Y' ? true : false, western == 'Y' ? true : false, published });
}
size_t i = 0, sum = 0;
for (Students S : std) {
if (S.exam > 80 && S.published)std[i].scholarship += 8000, sum += 8000;
if (S.exam > 85 && S.review > 80)std[i].scholarship += 4000, sum += 4000;
if (S.exam > 90)std[i].scholarship += 2000, sum += 2000;
if (S.exam > 85 && S.western)std[i].scholarship += 1000, sum += 1000;
if (S.review > 80 && S.leader)std[i].scholarship += 850, sum += 850;
i++;
}
std::pair<std::string, size_t> highest("", 0);
for (Students S : std) {
if (S.scholarship > highest.second) {
highest.first = S.name;
highest.second = S.scholarship;
}
}
std::cout
<< highest.first << std::endl
<< highest.second << std::endl
<< sum << std::endl;
return 0;
}
4
YaoLin 87 82 Y N 0
ChenRuiyi 88 78 N Y 1
LiXin 92 88 N N 0
ZhangQin 83 87 Y N 14
|
|