数据结构 2.验证表

问题描述

应用中有时需要验证来自不同地方的两个表的信息是否一致。本实验编写具有如下功能的程序:输入两个学生记录表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)

5
20120001 zhangli
20120002 wanglei
20120003 duyang
20120004 lixin
20120005 liufan
3
20120001 zhangli
20120006 lixin
20120002 wanglei

输出(1)

20120006 lixin is not in LIST1.

输入(2)

5
20120001 zhangli
20120002 wanglei
20120003 duyang
20120004 lixin
20120005 liufan
3
20120001 zhangli
20120004 wanglei
20120006 duyang

输出(2)

20120004 wanglei is not in LIST1.
20120006 duyang is not in LIST1.

输入(3)

5
20120001 zhangli
20120002 wanglei
20120003 duyang
20120004 lixin
20120005 liufan
3
20120001 zhangli
20120004 wanglei
20120006 duyang

输出(3)

the LIST2 is NULL.

输入(4)

5
20120001 zhangli
20120002 wanglei
20120003 duyang
20120004 lixin
20120005 liufan
0

输出(4)

the records of LIST2 are all in the LIST1.

代码

#include<stdio.h>  
#include<string.h>   
int main()  
{  
    int m,n;  
    scanf("%d",&m);  
    struct person  
    {     
        long int id;  
        char name[25];  
    };  
    struct person list1[m+1];  
    for(int i=1;i<=m;i++)  
    {  
        memset(list1[i].name,0,sizeof(list1[i].name));  
        scanf("%ld ",&list1[i].id);  
        scanf("%s",list1[i].name);  
    }  
    scanf("%d",&n);  
    if(n==0)  
    {  
        printf("the LIST2 is NULL.\n");  
    }  
    else  
    {  
        int count=0;  
        int flag=1;  
        struct person tmp;  
        for(int i=1;i<=n;i++)  
        {  
            count=0;  
            scanf("%ld ",&tmp.id);  
            scanf("%s",tmp.name);  
            for(int j=1;j<=m;j++)  
            {  
                if((tmp.id==list1[j].id)&&(strcmp(tmp.name,list1[j].name)==0))  
                {  
                    count=1;  
                    break;  
                }  
            }  
            if(count==0)  
            {  
                printf("%ld %s is not in LIST1.\n",tmp.id,tmp.name);  
                flag=0;  
            }  
        }   
        if(flag==1)  
        {  
            printf("the records of LIST2 are all in the LIST1.\n");  
        }     
    }  
    return 0;  
}  
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值