View Code of Problem 95

#include <iostream>
#include <cstring>

using namespace std;


struct student {
    string name;
    string sex;
    int year;
    int month;
    int day;
};

int main() {
    string work;
    cin >> work;
    struct student stuList[30];
    int n = 0;//人数
    while (work != "quit") {
        if (work == "add") {
            struct student stu;
            cin >> stu.name >>stu.sex>> stu.year >> stu.month >> stu.day;
            stuList[n] = stu;
            n++;
        } else if (work=="name"){
            string nameQue;
            cin>>nameQue;
            for (int i = 0; i < n; ++i) {
                if (stuList[i].name==nameQue){
                    cout<<stuList[i].name<<" "<<stuList[i].sex<<" "<<stuList[i].year<<"-"<<stuList[i].month<<"-"<<stuList[i].day<<endl;
                }
            }
        } else if (work=="sex"){
            string sexQue;
            cin>>sexQue;
            for (int i = 0; i < n; ++i) {
                if (stuList[i].sex==sexQue){
                    cout<<stuList[i].name<<" "<<stuList[i].sex<<" "<<stuList[i].year<<"-"<<stuList[i].month<<"-"<<stuList[i].day<<endl;
                }
            }
        }
        cin >> work;
    }
    return 0;
}

Double click to view unformatted code.


Back to problem 95