結果

問題 No.342 一番ワロタww
ユーザー mitsuo
提出日時 2016-05-09 22:59:59
言語 Java
(openjdk 23)
結果
AC  
実行時間 129 ms / 5,000 ms
コード長 1,080 bytes
コンパイル時間 2,103 ms
コンパイル使用メモリ 80,368 KB
実行使用メモリ 41,452 KB
最終ジャッジ日時 2024-10-15 13:24:14
合計ジャッジ時間 4,835 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 14
権限があれば一括ダウンロードができます

ソースコード

diff #

package jp.fedom.challange.yuki.l2.q342;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		List<String> input = new ArrayList<>();
		while (sc.hasNext()) {
			input.add(sc.nextLine());
		}

		System.out.println(solve(input));

		sc.close();
	}

	public static String solve(List<String> in) {
		String S = in.get(0);
		Pattern p = Pattern.compile("([^w]+)(w+)");
		Matcher m = p.matcher(S);

		StringBuilder sb = new StringBuilder();
		String d = System.lineSeparator();
		int max = 0;
		
		while (m.find()) {
			if (m.groupCount() == 2) {
				if (max == m.group(0).length() - m.group(1).length()) {
					sb.append(m.group(1)).append(d);
				} else if (max < m.group(0).length() - m.group(1).length()) {
					sb = new StringBuilder();
					sb.append(m.group(1)).append(d);
					max = m.group(0).length() - m.group(1).length();
				}
			}
		}

		return sb.toString().trim();
	}

}
0