View Code of Problem 95

#include <stdio.h>
#include <stdlib.h>
#include<ctype.h>
#include<string.h>
#include<math.h>
#include<stdbool.h>
int main()
{
	typedef struct
	{
		char name[10];
		char sex[10];
		int year, month, day;
	}student;
	student stu[30];
	int i, j;
	char a[10];
	i = 0;
	while (scanf("%s",a))
	{
		if (a[0] == 'q')
			break;
		else
		{
			switch (a[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", a); 
				for (j = 0; j < i; j++)
				{
					if (strcmp(a, stu[j].name) == 0)
					{
						printf("%s %s %d-%d-%d\n", stu[j].name, stu[j].sex, stu[j].year, stu[j].month, stu[j].day);
						break;
					}
				}
				break;
			case 's':scanf("%s", a);
					for (j = 0; j < i; j++)
					{
						if (strcmp(a, stu[j].sex) == 0)
						{
							printf("%s %s %d-%d-%d\n", stu[j].name, stu[j].sex, stu[j].year, stu[j].month, stu[j].day);
						}
					}
					break;
			default:
				break;
			}
		}
		
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 95