View Code of Problem 95

#include<bits/stdc++.h>
using namespace std;
struct student {
	string name;
	string sex;
	string birthday;
};
int main() {
	string order;
	vector<student> tongxue;
	while (cin >> order) {
		if (order == "quit")
			break;
		if (order == "add") {
			student newone;
			cin >> newone.name >> newone.sex;
			string year, month, day;
			cin >> year >> month >> day;
			newone.birthday = year + '-' + month + '-' + day;
			tongxue.push_back(newone);
		}
		if (order == "sex") {
			string xing;
			cin >> xing;
			for (auto i : tongxue) {
				if (i.sex == xing) {
					cout << i.name << " "<<i.sex << " " << i.birthday << endl;

				}
			}
		}
		if (order == "name") {
			string mingzi;
			cin >>mingzi;
			for (auto i : tongxue) {
				if (i.name == mingzi) {
					cout << i.name << " "<<i.sex << " " << i.birthday << endl;

				}
			}
		}
	}
}

Double click to view unformatted code.


Back to problem 95