作业帮 > 综合 > 作业

c++ACM简单题Description Given two integer sequences A and

来源:学生作业帮 编辑:拍题作业网作业帮 分类:综合作业 时间:2024/05/01 14:38:59
c++ACM简单题
Description
 
Given two integer sequences A and B,you are to find A-B,the difference of them, (i.e.,the elements that are in A but not in B),and ouput them in increasing order.Equal elements should be treated as the same.
Input
Input consists of multiple test cases.The first line of input contains a positive integer T,the number of test cases.Each test case consists of two lines.The first line begins with an integer N,followed by N integers for the sequence A.The second line begins with an integer M,followed by M integers for B.0<=N,M<=1000,and all the integers are within the scope of the type int.
 
Output
For each test case,output on a single line the difference of the two sequeces in increasing order.

#include
#include
int IsInSet(int a[ ], int n, int key) { //设数组下标从1开始
for(int i = n, a[0] = key; a[i] != key; i--);
return i;
}
void InsertElem(int set[ ], int &len, int key) {
for(int i = len; key < a[i] && i > 0; i--) set[i + 1] = set[i];
set[i + 1] = key;
len++;
}
void main( ) {
//考虑到测试用例的组数及每组数据量具有很大不确定性,所以用动态存储空间
int **set_a, **set_b, **set_c;
int n, *len_a, *len_b, *len_c, i, j;
cin >> n;
set_a = new int*[n];
set_b = new int*[n];
set_c = new int*[n];
len_a = new int[n];
len_b = new int[n];
len_c = new int[n];
for(i = 0; i < n; i++) len_c[i] = 0;
for(i = 0; i < n; i++) // 输入n组测试用例
{
cin >> len_a[i]; //集合a的长度
set_a[i] = new int[len_a[i] + 1];
set_c[i] = new int[len_a[i] + 1];
for(j = 1; j > set_a[i][j];
cin >> len_b[i];
for(j = 1; j > set_b[i][j];
}
for(i = 0; i < n; i++) //对n组测试用例进行处理
{
for(j = 1; j