#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
class Student
{
public:
int m_Score;
string m_Name;
};
vector<Student>v1;
struct Rule
{
bool operator()(Student& s1,Student& s2)
{
return s1.m_Score > s2.m_Score;
}
};
class Isname
{
public:
string m;
Isname(string name)
{
m = name;
}
bool operator()(Student s)
{
return s.m_Name == m;
}
};
int main()
{
vector<Student>v;
char m;
while (cin >> m)
{
switch (m)
{
case 'A':
{
Student s1;
cin >> s1.m_Name;
cin >> s1.m_Score;
if (!v.empty())
{
vector<Student>::iterator it = find_if(v.begin(), v.end(), Isname(s1.m_Name));
if (it != v.end())
{
(*it).m_Score = s1.m_Score;
}
else
{
v.push_back(s1);
}
}
else
{
v.push_back(s1);
}
break;
}
case'R':
{
string temp;
cin >> temp;
vector<Student>::iterator it = find_if(v.begin(), v.end(), Isname(temp));
if (it != v.end())
{
v.erase(it);
}
break;
}
case'P':
{
if (!v.empty())
{
for (vector<Student>::iterator it = v.begin(); it != v.end(); it++)
{
cout << (*it).m_Name << " " << (*it).m_Score << endl;
}
}
else
{
cout << "[空]" << endl;
}
break;
}
case'S':
{
sort(v.begin(), v.end(), Rule());
break;
}
}
}
return 0;
}
头歌实训项目【动态学生信息管理】
于 2022-05-15 16:26:53 首次发布