验证表(10分)

验证表(10分)

成绩10开启时间2018年10月4日 星期四 15:50
折扣0.8折扣时间2018年10月24日 星期三 15:50
允许迟交关闭时间2018年11月4日 星期日 15:50

验证表(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.

#include "stdio.h"
#include "stdlib.h"
#include "string.h"
typedef struct LIST{
    long id;
    char name[15];
    struct LIST *next;
} NODE;

int main(int argc, char const *argv[])
{
    NODE *head, *p, *q, *head2;
    int n, flag = 0, count = 0;
    scanf("%d", &n);

    head =  (NODE *)malloc(sizeof(NODE));
    head->next = NULL;
    q = head;

    for (int i = 0; i < n; i++){
        p = (NODE*)malloc(sizeof(NODE));
        for (int k = 0; k < 15; k++)
            (*p).name[k] = '\0';
        scanf("%ld %s", &p->id, &p->name);
        p->next = NULL;
        q->next = p;
        q = q->next;
    }

    scanf("%d", &n);
    if(n == 0){
        printf("the LIST2 is NULL.\n");
    }
    else{
        for (int i = 0; i < n; i++){
            flag = 0;
            p = (NODE*)malloc(sizeof(NODE));
            //存储这个数据
            for (int k = 0; k < 15; k++)
                (*p).name[k] = '\0';
            scanf("%ld %s", &p->id, &p->name);
            q = head;
            do{
                q = q->next;
                if (q->id == p->id && strcmp(p->name, q->name) == 0){
                    //printf("%8d %15s is not in LIST1\n", p->id, p->name);
                    flag = 1;
                    count++;
                    break;
                }
            } while (q->next != NULL);
            if(flag == 0){
                printf("%8d %s is not in LIST1.\n", p->id, p->name);
            }
        }
        if(count == n){
            printf("the records of LIST2 are all in the LIST1.\n");
        }
    }
}

 

  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值