People see people love A-B
Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 68543 Accepted Submission (s): 19203
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 INPUT3 3 1 2 3 1 4 73 7 2 5 8 2 3 4 5 6 7 8 0 0
Sample Output2 3 NULL
Authorlcy
Import Java.util.arraylist;import java.util.list;import Java.util.collections;import Java.util.Scanner;public class Main {public static void main (string[] args) {Scanner scan =new Scanner (system.in), while (Scan.hasnext ()) {int n= Scan.nextint (); int m=scan.nextint (); if (n==0&&m==0) break; List<integer> a=new arraylist<integer> (); List<integer> b=new arraylist<integer> (); for (int i=1;i<=n;i++) {int s=scan.nextint (); A.add (s);} for (int i=1;i<=m;i++) { int s=scan.nextint (); B.add (s);} A.removeall (b); Collections.sort (a); if (A.isempty ()) System.out.println ("NULL"); else {for (int i=0;i<a.size (); i++) {System.out.print (A.get (i) + "");} System.out.println ();}}}
(Java implementation) Hangzhou electric OJ 2034 people see Love A-B