1.

/**
* ACM Training 2009
* ACM Contest Problem # 19.09. "Exchanging Cards"
* Link: http://uva.onlinejudge.org/contests/227-44fb9aab/11678.pdf
*
* @author Felix Dietrich
* @version 1.0, 09/20/2009
*
* Methode: Tree sets, Comparison
* Status : Accepted
* Runtime: 0.160
*/

import java.util.*;

public class Main
{

public static void main(String... args)
{
Scanner sc = new Scanner(System.in);
Set<Integer> Aset = new TreeSet<Integer>();
Set<Integer> Bset = new TreeSet<Integer>();
int anum, bnum;

while(true)
{
Aset.clear();
Bset.clear();

anum = sc.nextInt();
bnum = sc.nextInt();

if(anum == 0 && bnum == 0)
return;

// fill card sets, eliminating double values by tree set
for(int i=0; i<anum; i++)
Aset.add(sc.nextInt());
for(int i=0; i<bnum; i++)
Bset.add(sc.nextInt());

// compare the sets
if(Aset.size() <= Bset.size())
{
System.out.println(compare(Aset, Bset));
}
else
System.out.println(compare(Bset, Aset));
}
}

/**
* smaller == smaller size
* @param aset smaller set
* @param bset greater set
* @return amount of different cards
*/
private static int compare(Set<Integer> smallerset, Set<Integer> biggerset)
{
int counter = 0;
for(Integer i: smallerset)
{
if(!biggerset.contains(i))
counter++;
}
return counter;
}
}


2.

/**
* ACM Training 2009
* ACM Problem #11678 - Cards' Exchange
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=78&page=show_problem&problem=2725
*
* @author Dennis Wilfert
* @version 1.0, 09/20/2009
*
* Status : Accepted
* Runtime: 0.360
*/
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.StringTokenizer;

public class Main {

public static void main(String[] args) throws IOException {

BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
PrintWriter writer = new PrintWriter(new BufferedOutputStream(System.out));
StringTokenizer token;

token = new StringTokenizer(reader.readLine());
int p1 = Integer.parseInt(token.nextToken());
int p2 = Integer.parseInt(token.nextToken());

int s1, s2;
HashSet<Integer> h1 = new HashSet<Integer>();
HashSet<Integer> h2 = new HashSet<Integer>();

while (p1 != 0 || p2 != 0) {

s1 = s2 = 0;
h1.clear();
h2.clear();

token = new StringTokenizer(reader.readLine());
// Werte für die erste Person in h1
while(p1 > 0){
h1.add(Integer.parseInt(token.nextToken()));
p1--;
}

token = new StringTokenizer(reader.readLine());
// Werte für die zweite Person in h2
while(p2 > 0){
h2.add(Integer.parseInt(token.nextToken()));
p2--;
}
// Schauen wieviele Werte von h1 nicht in h2 sind
for(int i: h1){
if(!h2.contains(i))
s1++;
}
// Schauen wieviele Werte von h2 nicht in h1 sind
for(int i: h2){
if(!h1.contains(i))
s2++;
}
// Den kleineren der beiden Werte ausgeben
writer.println(s1 < s2 ? s1 : s2);

token = new StringTokenizer(reader.readLine());
p1 = Integer.parseInt(token.nextToken());
p2 = Integer.parseInt(token.nextToken());
}

writer.flush();
}
}