View Code of Problem 95

#include <stdio.h>
#include <stdlib.h>
#include<ctype.h>
#include<string.h>
#include<math.h>
int main()
{
	 struct hero
	{
		 char name[20];
		 char sex[20];
		 int year, month, day;
	}stu[30];
	char ch[10];
	int i = 0,flag,k;
	while (scanf("%s",ch))
	{
		if (ch[0] == 'q')
			break;
		switch (ch[0])
		{
			
			case 'a':scanf("%s%s%d%d%d", stu[i].name, stu[i].sex, &stu[i].year, &stu[i].month, &stu[i].day);
				i++;
				break;
			case 'n':scanf("%s", ch);
				for ( k = 0; k < i; k++)
				{
					flag = 0;
						if (ch[0] = stu[k].name[0])
						{
							for (int j = 0; j < strlen(ch); j++)
							{
								if (ch[j] == stu[k].name[j])
									flag = 1;
								else {
									flag = 0;
									break;
								}
							}
						}
						if (flag == 1)
						 break;
				}
				printf("%s %s %d-%d-%d\n", stu[k].name, stu[k].sex, stu[k].year, stu[k].month, stu[k].day);
				break;
			case 's':scanf("%s", ch);
				
					for ( k = 0; k < i; k++)
					{
						if(stu[k].sex[0]==ch[0])
							printf("%s %s %d-%d-%d\n", stu[k].name, stu[k].sex, stu[k].year, stu[k].month, stu[k].day);
					}
					break;
				
				
				
				
			default:
			break;
		}
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 95