3852 - left 消せ
2012/09/28
java
pku
poj
もっと効率いい方法があるのだろうけど、とりあえず。
package p3852;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
do {
int n = Integer.parseInt(scanner.nextLine());
if (n == 0)
break;
List list = new ArrayList();
for (int i = 0; i < n; i++) {
String line = scanner.nextLine();
list.add(line);
}
int ret = 0;
b: for (int j = 0; j < 100; j++) {
List list2 = new ArrayList();
for (int i = 0; i < n; i++) {
String line = list.get(i);
if (!(j < line.length()))
break b;
String s = line.substring(j);
if (list2.contains(s))
break b;
list2.add(s);
}
ret = j;
}
System.out.println(ret);
} while (true);
}
}
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
do {
int n = Integer.parseInt(scanner.nextLine());
if (n == 0)
break;
List
for (int i = 0; i < n; i++) {
String line = scanner.nextLine();
list.add(line);
}
int ret = 0;
b: for (int j = 0; j < 100; j++) {
List
for (int i = 0; i < n; i++) {
String line = list.get(i);
if (!(j < line.length()))
break b;
String s = line.substring(j);
if (list2.contains(s))
break b;
list2.add(s);
}
ret = j;
}
System.out.println(ret);
} while (true);
}
}
: