验证表(BIT)

应用中有时需要验证来自不同地方的两个表的信息是否一致。本实验编写具有如下功能的程序:输入两个学生记录表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. 5↵
  2. 20120001 zhangli↵
  3. 20120002 wanglei↵
  4. 20120003 duyang↵
  5. 20120004 lixin↵
  6. 20120005 liufan↵
  7. 3↵
  8. 20120001 zhangli↵
  9. 20120006 lixin↵
  10. 20120002 wanglei↵
以文本方式显示
  1. 20120006 lixin is not in LIST1.↵
1秒64M0
测试用例 2以文本方式显示
  1. 5↵
  2. 20120001 zhangli↵
  3. 20120002 wanglei↵
  4. 20120003 duyang↵
  5. 20120004 lixin↵
  6. 20120005 liufan↵
  7. 3↵
  8. 20120001 zhangli↵
  9. 20120004 wanglei↵
  10. 20120006 duyang↵
以文本方式显示
  1. 20120004 wanglei is not in LIST1.↵
  2. 20120006 duyang is not in LIST1.↵
1秒64M0
测试用例 3以文本方式显示
  1. 5↵
  2. 20120001 zhangli↵
  3. 20120002 wanglei↵
  4. 20120003 duyang↵
  5. 20120004 lixin↵
  6. 20120005 liufan↵
  7. 0↵
以文本方式显示
  1. the LIST2 is NULL.↵
1秒64M0
测试用例 5以文本方式显示
  1. 5↵
  2. 20120001 zhangli↵
  3. 20120002 wanglei↵
  4. 20120003 duyang↵
  5. 20120004 lixin↵
  6. 20120005 liufan↵
  7. 3↵
  8. 20120002 wanglei↵
  9. 20120001 zhangli↵
  10. 20120004 lixin↵
以文本方式显示
  1. the records of LIST2 are all in the LIST1.↵
1秒64M0
#include <stdio.h>  
#include <stdlib.h>  
#include <string.h>  
struct Student  
{  
    int id;  
    char name[50];  
};  
int compareStudents(const void* a, const void* b)  
{  
    return ((struct Student*)a)->id - ((struct Student*)b)->id;  
}  
int main() {  
    struct Student list1[100], list2[100], notInList1[100];  
    int n, i,j,m, p = 0;  
    scanf("%d", &n);  
    for (i = 0; i < n; i++)  scanf("%d %s", &list1[i].id, list1[i].name);  
    scanf("%d", &m);  
    for (i = 0; i < m; i++)  scanf("%d %s", &list2[i].id, list2[i].name);  
    if (m == 0) {  
        printf("the LIST2 is NULL.\n");  
        return 0;  
    }  
    qsort(list1, n, sizeof(struct Student), compareStudents);  
    qsort(list2, m, sizeof(struct Student), compareStudents);  
    for (i = 0; i < m; i++)  
    {  
        int found = 0;  
        for (j = 0; j < n; j++)  
        {  
            if (list2[i].id == list1[j].id && strcmp(list2[i].name, list1[j].name) == 0) {  
                found = 1;  
                break;  
            }  
        }  
        if (!found)  notInList1[p++] = list2[i];  
    }  
    if (!p)  printf("the records of LIST2 are all in the LIST1.\n");  
    else  
    {  
        for (i = 0; i < p; i++)  printf("%d %s is not in LIST1.\n", notInList1[i].id, notInList1[i].name);  
    }  
    return 0;  
} 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值