View Code of Problem 95

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
struct Message{
    char name[20];
    char sex[6];
    int y,m,d;
}mes[30];
int main(){
    char a[999],n[999],s[999];
    int i=0;
    while(cin>>a){
    if(strcmp(a,"quit")==0){
        break;
    }
    else if(strcmp(a,"add")==0){
        cin>>mes[i].name>>mes[i].sex>>mes[i].y>>mes[i].m>>mes[i].d;
        i++;
    }
//        for(int j=0;j<i;j++){
//        cout<<mes[j].name;
//    }
    else if(strcmp(a,"name")==0){
        cin>>n;
        for(int j=0;j<i;j++){
            if(strcmp(n,mes[j].name)==0)
                cout<<mes[j].name<<" "<<mes[j].sex<<" "<<mes[j].y<<"-"<<mes[j].m<<"-"<<mes[j].d<<endl;
        }
    }
    else if(strcmp(a,"sex")==0){
        cin>>s;
        for(int j=0;j<i;j++){
            if(strcmp(s,mes[j].sex)==0){
                cout<<mes[j].name<<" "<<mes[j].sex<<" "<<mes[j].y<<"-"<<mes[j].m<<"-"<<mes[j].d<<endl;
            }
        }
    }
    }
    
    return 0;
}

Double click to view unformatted code.


Back to problem 95