题目
验证表(10分)
成绩: 10 / 折扣: 0.8
应用中有时需要验证来自不同地方的两个表的信息是否一致。本实验编写具有如下功能的程序:输入两个学生记录表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<math.h>
#include<malloc.h>
#include<string.h>
struct text{
int num;
char name[10];
};
int main()
{
int m,n,i,j;
int flag=0,flag1=0;
scanf("%d",&m);
struct text biao1[m];
for(i=0;i<m;i++)
{
memset(biao1[i].name,0,sizeof(biao1[i].name));
}
for(i=0;i<m;i++)
{
scanf("%d %s",&biao1[i].num,&biao1[i].name);
}
scanf("%d",&n);
struct text biao2[n+1];
for(i=0;i<=n;i++)
{
memset(biao2[i].name,0,sizeof(biao2[i].name));
}
for(i=0;i<n;i++)
{
scanf("%d %s",&biao2[i].num,&biao2[i].name);
}
for(i=0;i<n;i++)
{
flag1=0;
for(j=0;j<m;j++)
{
if(biao2[i].num==biao1[j].num)
{
if(strcmp(biao2[i].name,biao1[j].name)==0)
{
flag1++;
//printf("%d %s\n",biao2[i].num,biao2[i].name);
break;
}
}
}
if(flag1==0)
{
printf("%d %s is not in LIST1.\n",biao2[i].num,biao2[i].name);
flag++;
}
}
if(flag==0&&n!=0)
{
printf("the records of LIST2 are all in the LIST1.\n");
}
if(n==0)
{
printf("the LIST2 is NULL.\n");
}
}