您的位置:首页 > 编程语言 > C语言/C++

PAT乙级1004. 成绩排名 C++

2016-07-23 16:29 465 查看


一个简单的存储处理与读取的题目,并不难,但是没有很规范的写,应该写getter setter 方法的,嘿嘿,偷懒了,希望机智的小伙伴们不要这样。祝大家变成顺利!

#include <iostream>
#include <string>
using namespace std;

class Score
{
public:
string name;
string number;
unsigned score;

void display();
};//类的结尾要写分号哦~
void Score::display()
{
cout<<name<<" "<<number<<endl;
}
int main()
{
int input_times=0;//用户输入的次数
cin>>input_times;
Score* s=new Score[input_times];
//用户初始化数组
for(int i=0;i<input_times;i++)
{
cin>>s[i].name;
cin>>s[i].number;
cin>>s[i].score;
}
//寻找最好成绩和最差成绩下标
unsigned best_index=0;
unsigned worest_index=0;
for(int i=1;i<input_times;i++)
{
if(s[i].score<s[worest_index].score)
{
worest_index=i;
}
if(s[i].score>s[best_index].score)
{
best_index=i;
}
}
//输出
s[best_index].display();
s[worest_index].display();
//释放资源
delete[] s;
system("pause");
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: