Problem:
The title does not order the a[] array before sorting, resulting in a non-pass.
The subject uses a string to store the required array elements, the output is convenient, but also more flexible.
People see people love A-BTime
limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 53264 Accepted Submission (s): 15008
Problem description participated in the last month of the students must remember one of the simplest of the topic, is {a}+{b}, the topic of the two set of the set, today we ask for a A-B is the difference of two sets, is to do the subtraction operation of the set. (Of course, we all know that the definition of a collection is that there are not two identical elements in the same set, so here's a reminder)
Oh, very simple, right?
Input data for each set of 1 rows, the beginning of each row of data is 2 integers n (0<=n<=100) and M (0<=m<=100), respectively, the number of elements of collection A and set B, followed by n+m elements, the first n elements belong to set a, The rest belongs to set B. Each element is an integer that does not exceed the int range, and the elements are separated by a space.
If N=0 and m=0 represent the end of the input, do not do the processing.
Output outputs a row of data for each set of data, representing the result of a-B, and output "null" If the result is an empty collection, otherwise, from small to large output, 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
Code:
Import java.util.*;p ublic class main{public static void Main (String args[]) {Scanner cin=new Scanner (system.in); while ( Cin.hasnext ()) {int n=cin.nextint (); int m=cin.nextint (); if (m==0&&n==0) break;else{int[] a=new int[n];int[] b= New Int[m];int k;for (int i=0;i<n;i++) a[i]=cin.nextint (); for (int i=0;i<n-1;i++) for (int j=i+1;j<n;j++) {if (a[ I]>a[j]) {k=a[j];a[j]=a[i];a[i]=k;}} for (int i=0;i<m;i++) b[i]=cin.nextint (); String s= ""; for (int i=0;i<a.length;i++) {int t=0;for (int j=0;j<b.length;j++) {if (A[i]==b[j]) {t=1;break;}} if (t==0) s+=a[i]+ "";} if (s== "") System.out.println ("NULL"); ElseSystem.out.println (s);}}}
HDU 2034 People see people love A-B (Java)