Skip to content

Instantly share code, notes, and snippets.

@zzzz465
Created June 7, 2019 06:28
Show Gist options
  • Save zzzz465/1560ad0510d2802318d71afe35e5f635 to your computer and use it in GitHub Desktop.
Save zzzz465/1560ad0510d2802318d71afe35e5f635 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <string.h>
typedef struct _Data
{
char NationalName[5];
int NationalCode;
} Data;
int main()
{
Data DataArr[100];
int count = 0;
while(1)
{
char buffer[10] = { '\0', };
gets(buffer);
if((buffer[0] == '^') && (buffer[1] == 'Z'))
break;
Data *p = &DataArr[count];
sscanf(buffer, "%s %d", p->NationalName, &(p->NationalCode));
count++;
}
while(1)
{
char buffer[10];
int flag = 1;
gets(buffer);
if((buffer[0] == '^') && (buffer[1] == 'Z'))
return 0;
for(int i = 0; i < count; i++)
{
if(strcmp(DataArr[i].NationalName, buffer) == 0)
{
printf("%s %d\n", DataArr[i].NationalName, DataArr[i].NationalCode);
flag = 0;
break;
}
}
if(flag)
{
printf("not exist\n");
flag = 1;
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment