View Code of Problem 95

#include<math.h>
#include<stdio.h>
#include<string.h>
typedef struct{
char name[20];
char sex[10];
int y,m,d;	
}stu;
int main(){
	int i=0,j; 
	stu s[20];
	char commend[30];
	char name[20];
	char sex[10];
	while(scanf("%s",commend)!=EOF)
	{
		if(strcmp(commend,"add")==0)
		{
			scanf("%s %s %d %d %d",s[i].name,s[i].sex,&s[i].y,&s[i].m,&s[i].d);
			i++;
		}
		if(strcmp(commend,"name")==0)
		{
			scanf("%s",name);
			if(i==0)
			{
				break;
			}
			else
			{
				for(j=0;j<i;j++)
				{
					if(strcmp(s[j].name,name)==0)
					{
						printf("%s %s %d-%d-%d\n",s[j].name,s[j].sex,s[j].y,s[j].m,s[j].d);
					}
				}
			}
		}
		if(strcmp(commend,"sex")==0)
		{
			scanf("%s",sex);
			if(i==0)
			{
				break;
			}
			else
			{
				for(j=0;j<i;j++)
				{
					if(strcmp(s[j].sex,sex)==0)
					{
						printf("%s %s %d-%d-%d\n",s[j].name,s[j].sex,s[j].y,s[j].m,s[j].d);
					}
				}
			}
		}
		if(strcmp(commend,"quit")==0)
		{
			return 0;
		}
	}
}

Double click to view unformatted code.


Back to problem 95