#include <iostream>
#include <map>
#include <string>
using namespace std;
class Students{
public:
string student;
string gender;
int times;
};
int main(){
map<string, string> mapstudent;
Students stu;
cout << "请输入学生数量:";
cin >> stu.times;
for(int i = 0; i < stu.times; ++i){
cout << "请输入学生姓名:";
cin >> stu.student;
cout << "请输入学生性别:";
cin >> stu.gender;
mapstudent[stu.gender] = stu.student;
}
for(auto it = mapstudent.begin(); it != mapstudent.end(); it++){
cout << "性别是:" << mapstudent.first() << "学生是:" << mapstudent.second() << endl;
}
}
使用了class map iostream string库,一大段代码。