新手入门,想用这个题目把最近学的都用上,所以代码比较多,欢迎各位大神指正

//以下代码通过了测试
#include<iostream>;
using namespace std;
#include<string>;
#include<cstdlib>;
#define MAX 100

struct student
{
string name;
int score1;
int score2;
string ad;
string area;
int essay;
int money = 0;
};

struct stubook
{
struct student stuarr[MAX];

int N;
};

void sure(struct stubook *stuarr)
{
for (int i = 0; i < stuarr->N; i++)
{
if (stuarr->stuarr[i].score1 > 80 && stuarr->stuarr[i].essay >= 1)
{
stuarr->stuarr[i].money += 8000;
}
if (stuarr->stuarr[i].score1 > 85 && stuarr->stuarr[i].score2 > 80)
{
stuarr->stuarr[i].money += 4000;
}
if (stuarr->stuarr[i].score1 > 90)
{
stuarr->stuarr[i].money += 2000;
}
if (stuarr->stuarr[i].score1 > 85 && stuarr->stuarr[i].area == "Y")
{
stuarr->stuarr[i].money += 1000;
}
if (stuarr->stuarr[i].score2 > 80 && stuarr->stuarr[i].ad == "Y")
{
stuarr->stuarr[i].money += 850;
}
}

}

int main()
{
struct stubook stuarr;

cin >> stuarr.N;

for (int i = 0; i < stuarr.N; i++)
{
cin >> stuarr.stuarr[i].name >> stuarr.stuarr[i].score1 >> stuarr.stuarr[i].score2
>> stuarr.stuarr[i].ad >> stuarr.stuarr[i].area >> stuarr.stuarr[i].essay;
}

sure(&stuarr);

int maxmoney = 0;

for (int i = 0; i < stuarr.N ; i++)
{
maxmoney = (maxmoney > stuarr.stuarr[i].money ? maxmoney : stuarr.stuarr[i].money);
}

string maxname;

for (int i = 0; i < stuarr.N; i++)
{
if (maxmoney == stuarr.stuarr[i].money)
{
maxname = stuarr.stuarr[i].name;
break;
}
}

int sum = 0;

for (int i = 0; i < stuarr.N; i++)
{
sum += stuarr.stuarr[i].money;
}

cout << maxname << endl;
cout << maxmoney << endl;
cout << sum << endl;

system("pause");

return 0;
}

1 条评论

  • 1

信息

ID
1001
难度
5
分类
模拟 点击显示
标签
递交数
37245
已通过
12252
通过率
33%
被复制
72
上传者