应用中有时需要验证来自不同地方的两个表的信息是否一致。本实验编写具有如下功能的程序:输入两个学生记录表LIST1,LIST2,在表LIST2中找出所有没有在表LIST1中出现的学生记录(设表LIST1为基础数据表,非空)。
每一个学生记录元素包含两个数据项:学号(整数),姓名;
如果学生记录表LIST2中的记录都包含在LIST1中,则输出the records of LIST2 are all in the LIST1.
如果学生记录表LIST2中的存在学号,姓名不能与表LIST1完全匹配的记录,则输出 学号(%8d)姓名(%15s)is not in LIST1.
如果LIST2为空表,则输出the LIST2 is NULL.
测试输入![]() | 期待的输出![]() | 时间限制![]() | 内存限制![]() | 额外进程![]() | |
---|---|---|---|---|---|
测试用例 1 | 以文本方式显示
| 以文本方式显示
| 1秒 | 64M | 0 |
测试用例 2 | 以文本方式显示
| 以文本方式显示
| 1秒 | 64M | 0 |
测试用例 3 | 以文本方式显示
| 以文本方式显示
| 1秒 | 64M | 0 |
测试用例 5 | 以文本方式显示
| 以文本方式显示
| 1秒 | 64M | 0 |
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
int n1,n2,i,j,judge,all=0;
scanf("%d\n",&n1);
char list1[n1][25];
for(i=0;i<n1;i++) gets(list1[i]);
scanf("%d\n",&n2);
char list2[n2][25];
int out[n2],k=0;
out[0]=0;
for(j=0;j<n2;j++) gets(list2[j]);
if(n2==0) printf("the LIST2 is NULL.\n");
else
{
for(j=0;j<n2;j++)
{
all=0;
for(i=0;i<n1;i++)
{
judge=strcmp(list2[j],list1[i]);
if(judge!=0) all+=1;
}
if(all==n1) //此项不在表一中
{
out[k]=j;
k++;
}
}
if(k>0) //表二存在项不在表一中
{
for(i=0;i<k;i++) printf("%s is not in LIST1.\n",list2[out[i]]);
}
else printf("the records of LIST2 are all in the LIST1.\n"); //表二全部在表一中
}
}