blob: 2c4681b9e47d64b533370c05e24dccc8db580b8a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
package problemas;
import java.util.ArrayList;
public class Problema214AbdicacionDeUnRey {
static java.util.Scanner in;
public static void main(String args[]) {
in = new java.util.Scanner(System.in);
int reyesDinastia = in.nextInt();
while ( reyesDinastia != 0 ) {
casoDePrueba(reyesDinastia);
System.out.println();
reyesDinastia = in.nextInt();
}
}
public static void casoDePrueba(int reyesDinastia) {
ArrayList<String> reyes = new ArrayList<>();
int[] numeros = new int[20];
String nombre;
for ( int i = 0; i < reyesDinastia; i++ ) {
nombre = in.next();
if ( reyes.contains(nombre) ) {
numeros[reyes.indexOf(nombre)]++;
}
else {
reyes.add(nombre);
numeros[reyes.indexOf(nombre)] = 1;
}
}
int herederos = in.nextInt();
for ( int i = 0; i < herederos; i++ ) {
nombre = in.next();
if ( reyes.contains(nombre) ) {
numeros[reyes.indexOf(nombre)]++;
System.out.println(numeros[reyes.indexOf(nombre)]);
}
else {
reyes.add(nombre);
numeros[reyes.indexOf(nombre)] = 1;
System.out.println(1);
}
}
}
}
|