离散题目6

来源:互联网 发布:中信银行软件 编辑:程序博客网 时间:2024/06/07 05:33

Problem Description

bLue 最近忙于收集卡片,已知可收集的卡片一共有 n 种,每种卡片都有唯一的编号。 现在给出 bLue 已经收集到的 m 种卡片,你能告诉他剩下的没收集到的卡片都有什么吗?

Input

多组数据,到 EOF 结束(数据组数不超过 100)。

每组数据第一行输入 2 个整数 n (1 <= n <= 100), m (1 <= m <= n),分别表示卡片总的种类数和 bLue 已经收集到的种类数。

第二行输入 n 个从小到大给出的用空格分隔的整数,表示所有可收集卡片的编号。

第三行输入 m 个从小到大给出的用空格分隔的整数,表示 bLue 收集到的 m 种卡片的编号。

所有的编号都在 1~100 之间。

Output

对于每组数据,第一行输出一个整数,表示没有收集到的卡片有多少种,如果大于 0,则在下一行再按从小到大输出具体的编号。

Example Input

5 31 2 3 4 51 3 53 31 2 31 2 3

Example Output

22 40

Hint

第一组示例可以看作: U = {1, 2, 3, 4, 5},A = {1, 3, 5},答案即为 A 在 U 中的补集 C = {2, 4}。

code:

#include <stdio.h>#include <string.h>int main(){    int n, m, i, t, x;    int a[120], b[120], c[120];    while(~scanf("%d%d", &n, &m))    {        t = 0;        memset(a, 0, sizeof(a));        memset(b, 0, sizeof(b));        for(i = 0;i<n;i++)        {            scanf("%d", &x);            a[x]++;        }        for(i = 0;i<m;i++)        {            scanf("%d", &x);            b[x]++;        }        for(i = 0;i<110;i++)        {            if(a[i]==1&&b[i]==0)            {                c[t++] = i;            }        }        printf("%d\n", t);        if(t!=0)        {            for(i = 0;i<t;i++)            {                if(i==t-1) printf("%d\n", c[i]);                else printf("%d ", c[i]);            }        }    }}