#include<iostream> #include<vector> #include<algorithm> #include<string> #include<climits> #include<cmath> #include<unordered_map> using namespace std; struct info { string name; string male; string year; string month; string day; }; int main() { string order; unordered_map<string, string> map; vector<string> boys; vector<string> girls; while (cin >> order) { if (order == "quit") break; if (order == "add") { info person; cin >> person.name >> person.male >> person.year >> person.month >> person.day; string all_info = person.name + " " + person.male + " " + person.year + "-" + person.month + "-" + person.day; map[person.name] = all_info; if (person.male == "Male") boys.push_back(all_info); else girls.push_back(all_info); } if (order == "name") { string name; cin >> name; cout << map[name] << endl; } if (order == "sex") { string male; cin >> male; if (male == "Male") { for (int i = 0; i < boys.size(); i++) cout << boys[i] << endl; } else for (int i = 0; i < girls.size(); i++) cout << girls[i] << endl; } } } |
Double click to view unformatted code.