PTA 集合减法
给定两个非空集合A和B,集合的元素为30000以内的正整数,编写程序求A-B。
输入格式:
输入为三行。第1行为两个整数n和m,分别为集合A和B包含的元素个数,1≤n, m ≤10000。第2行表示集合A,为n个空格间隔的正整数,每个正整数不超过30000。第3行表示集合B,为m个空格间隔的正整数,每个正整数不超过30000。
输出格式:
输出为一行整数,表示A-B,每个整数后一个空格,各元素按递增顺序输出。若A-B为空集,则输出0,0后无空格。
输入样例:
5 5
1 2 3 4 5
3 4 5 6 7
输出样例:
1 2
我的代码:(他不能够输出结果,不知道为什么)
#include<iostream>
using namespace std;
typedef struct{
int *elem;
int length;
}Sqlist;
void createList(Sqlist &L){
L.elem=new int[100];
int n;
cin>>n;
for(int i=0;i<n;i++){
cin>>L.elem[i];
}
}
void declineList(Sqlist L1,Sqlist L2){
for(int i=0;i<L2.length;i++){
for(int j=0;j<L1.length;j++){
if(L2.elem[i]==L1.elem[j])
cout<<L2.elem[i]<<" ";
}
}
}
int main(){
Sqlist L1,L2;
createList(L1);
createList(L2);
declineList(L1,L2);
return 0;
}
输出结果:输不出来,我还有其他错误的地方,但我最想知道我的结果为什么输不出来?
希望各位大佬能够指点我SOS![没有输出结果](https://img-blog.csdnimg.cn/2021040323593962.png#pic_center)