Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 2034
People love A-B
Time Limit: 2000/1000 MS (Java/others) memory limit: 65536/32768 K (Java/Others)
Total submission (s): 43093 accepted submission (s): 12090
The person who participated in the Problem description last month's competition must remember one of the simplest questions: {A} + {B}. The question is the union of the two sets, today, our A-B calculates the difference between the two sets, that is, the subtraction operation of the Set. (Of course, we all know the definition of a set, that is, there will not be two identical elements in the same set. Here, I would like to remind you)
It's easy, right?
Each input group occupies one row. Each row starts with two integers, n (0 <= n <= 100) and M (0 <= m <= 100 ), indicates the number of elements of set a and Set B respectively, followed by N + M elements. The first n elements belong to set a, and the rest belong to Set B. each element is an integer not greater than the int value range. Each element is separated by a space.
If n = 0 and m = 0, the input ends without processing. Output outputs a line of data for each group of data, indicating the results of the A-B, if the results are empty set, the output "null", otherwise the output results from small to large, to simplify the problem, each element is followed by a space.
Sample Input
3 3 1 2 3 1 4 73 7 2 5 8 2 3 4 5 6 7 8 0 0
Sample output
2 3 NULL
Simple question. Just be careful.
AC code:
<span style="font-size:24px;">#include<iostream>#include<cstring>#include<algorithm>using namespace std;int cmp(int a,int b){return a<b;}int main(){int a[101],b[101],c[101],m,n,i,j,k;while(~scanf("%d%d",&m,&n)){memset(a,0,sizeof(a));memset(b,0,sizeof(b));memset(c,0,sizeof(c));if(m==0&&n==0)break;for(i=0;i<m;i++)scanf("%d",&a[i]);for(j=0;j<n;j++)scanf("%d",&b[j]);for(i=0;i<n;i++){for(j=0;j<n;j++){if(a[i]==b[j])a[i]=0;continue;}}k=0;for(i=0;i<m;i++){if(a[i]!=0){c[k]=a[i];k++;}}sort(c,c+k,cmp);if(k==0)printf("NULL\n");else{for(i=0;i<k;i++)printf("%d ",c[i]);printf("\n");}}return 0;}</span>
Hangzhou 2034 people love A-B