[c++]代码库
#include<iostream>
#include<string>
using namespace std;
class Student
{
private:
string name;
int score;
public:
Student()
{
name="NULL";
score=0;
}
void setStudent(string n,int s)
{
name=n;
score=s;
}
int operator>(Student &s)
{
if(score>s.score)
return 1;
else if((score==s.score)&&(name<s.name))
return 1;
else
return 0;
}
friend ostream& operator<<(ostream &,Student &);
};
ostream& operator<<(ostream &os,Student &s)
{
os<<s.score<<" "<<s.name;
return os;
}
int main()
{
int cases;
string name;
int score;
cin>>cases;
Student students[cases], temp;
for (int i = 0; i < cases; i++)
{
cin>>name>>score;
students[i].setStudent(name, score);
}
for (int i = 0; i < cases; i++)
{
for (int j = 0; j < cases - i - 1; j++)
{
if (!(students[j] > students[j + 1]))
{
temp = students[j];
students[j] = students[j + 1];
students[j + 1] = temp;
}
}
}
for (int i = 0; i < cases; i++)
cout<<students[i]<<endl;
return 0;
}
by: 发表于:2017-09-01 09:53:37 顶(0) | 踩(0) 回复
??
回复评论