有一群学生排着队,现在知道每一个人的学号,需要确认学号是否按照从小到大的顺序排列好了
在本例中,学号为"210103"的有两个人,但是不影响结果
#include<iostream>
#include<cstdlib>
#include<string>
#include<vector>
#include<algorithm>
class Student
{
private:
std::string stu_no;
std::string name;
public:
explicit Student(std::string stu_no, std::string name) :stu_no(stu_no), name(name) {}
bool operator<(const Student& stu) { return stoi(this->stu_no) < stoi(stu_no); }
};
using namespace std;
int main()
{
vector<Student> stuVec;
stuVec.push_back(Student("210101", "王二"));
stuVec.push_back(Student("210102", "张三"));
stuVec.push_back(Student("210103", "李四"));
stuVec.push_back(Student("210103", "李五"));
stuVec.push_back(Student("210104", "麻六"));
bool result = is_sorted(stuVec.begin(), stuVec.end());
if (result) {
cout << "学号按照从小到大的顺序排列好了" << endl;
}
else
{
cout << "学号有点混乱" << endl;
}
return EXIT_SUCCESS;
}
|