C language_0404 exercise_structure: 11-1 structure + array/search and output by subscript

11-1. Entry and display of address book (10)

A record in the address book contains the following basic information: friend's name, date of birth, gender, landline phone number, mobile phone number. This question requires writing a program, entering N records, and displaying any record according to the requirements.

Input format:

Enter a positive integer N (<=10) in the first line; then N lines, each line gives a record according to the format "name, birthday, gender, fixed-line phone". The "name" is a non-empty string of no more than 10 characters and does not contain spaces; the birthday is given in the format of "yyyy/mm/dd"; the gender is represented by "M" for "male" or "F" Indicates "female"; both "fixed line" and "mobile phone" are consecutive numbers with no more than 15 digits, and "+" may appear in front.

After the address book record input is completed, the last line gives a positive integer K, and then K integers are given, indicating the record number to be queried (numbered sequentially from 0 to N-1). Separate numbers with spaces.

Output format:

For each record number to be queried, output the record in a row in the format of "name, landline, mobile phone, gender, birthday". If the queried record does not exist, output "Not Found".

Input example:

 

#include <stdio.h>
typedef struct info {
	char name[10];
//	char[10] name; 字符串数组的定义!!有点忘记了! 
	char birth[11] ;
	char gen[2];
	char number1[17];
	char number2[17];
}Info;//这里只有一个分号!!! 
	
	int main()
	{
		int num,i=0;
		int k=0,f; 
		scanf("%d",&num);
		
		Info tele[100]; 
		while(i!=num)
		{
			scanf("%s %s %s %s %s",&tele[i].name,&tele[i].birth
			,&tele[i].gen,&tele[i].number1,&tele[i].number2);
			//每行按照格式“姓名 生日 性别 固话 手机”给出一条记录
			i ++;
		}
		scanf("%d",&k);//寻找的个数 
		while(k!=0)
		{
			scanf("%d",&f);
			//f在0-num-1 才是有效的 
			if(f>=0&&f<=(num-1)){
				//按照“姓名 固话 手机 性别 生日”的格式输出该记录
				printf("%s %s %s %s %s\n",tele[f].name,tele[f].number1,
				tele[f].number2,tele[f].gen,tele[f].birth);
			}
			else 
			{
				printf("Not Found\n");
			}
			k --;
		}
	
	}

Guess you like

Origin blog.csdn.net/Shmily_as33/article/details/129947027