杭電oj 2034
阿新 • • 發佈:2021-01-30
技術標籤:杭電
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main(){
int n,m;
while(cin >> m >> n){
int a[120] = {0},b[120] = {0},c[120] = {0};
if(m == 0 && n == 0){//停止執行
break;
}
int i,j,x;
for(i = 0; i < m; i++){//陣列賦值
cin >> x;
a[i] = x;
}
for(j = 0; j < n; j++){//陣列賦值
cin >> x;
b[j] = x;
}
int t = 0,y = 0;
for(i = 0; i < m; i++){//比較A中元素是否在B中
for(j = 0; j < n; j++){
if(a[i] == b[j])t = 1;
}
if(t == 0){//如果A中元素不在B中,把該值賦給c,並使長度加一
c[y] = a[i];
y++ ;
}
t = 0;
}
sort(c,c+y);//排序c中元素
if(y == 0)//A是B的子集
cout << "NULL";
else//逐位輸出
for(i = 0; i < y; i++)cout << c[i] << " ";
cout << endl;
}
return 0;
}