离散题目6
来源:互联网 发布:宝贝关键词怎么优化 编辑:程序博客网 时间:2024/06/06 08:43
离散题目6
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}。
代码
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int m, n;
int s[205], t[205], a[205];
while(cin>>m>>n)
{
for(int i = 0; i < m; i++)
{
cin>>s[i];
}
for(int i = 0; i < n; i++)
{
cin>>t[i];
}
sort(s, s+m);
sort(t, t+n);
int cnt = 0;
int q = 0;
for(int i = 0; i < m; i++)
{
for(int j = 0; j < n; j++)
{
if(t[j] == s[i])
break;
else
{
if(j == n-1)
{
cnt++;
a[q++] = s[i];
}
}
}
}
if(cnt == 0)
cout<<cnt<<endl;
else
{
cout<<cnt<<endl;
for(int p = 0; p < cnt; p++)
{
if(p == cnt-1)
cout<<a[p]<<endl;
else
cout<<a[p]<<" ";
}
}
}
}
- 3800-->离散题目6
- 离散题目6
- 离散题目6
- 离散题目6
- 离散题目6
- 离散题目6 求补集
- sdut-离散题目6
- 离散题目6(求补集)
- SDUT 3800 离散题目6
- 离散题目3
- 离散题目7
- sdut离散题目11
- sdut离散题目13
- sdut离散题目14
- 离散题目12
- 离散题目15
- 3799-->离散题目5
- 离散题目1
- Requires development platform O but this is a release platform
- angularJs获取点击的元素
- 程序猿学习第十天,定位网页元素
- oracle10g job管理
- javaScript对象
- 离散题目6
- nginx 基本介绍liunx 下载 安装 启动
- 文件系统优化
- linux 下jdk和tomcat的安装部署
- Shell编程之统计英文文本的单词及频数
- a+b problem(EOF)
- muleESB简介和安装(一)
- 写爬虫时一些可以用的代理
- Java 数组