Loading...

3852 - left 消せ

もっと効率いい方法があるのだろうけど、とりあえず。

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);
    }
}
リアクション: 
poj 6055018935407843242

コメントを投稿

ホーム item

このブログを検索

Random Posts

Popular Posts

Labels

ADS