結果

問題 No.342 一番ワロタww
ユーザー face4face4
提出日時 2018-05-20 11:47:46
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,572 bytes
コンパイル時間 2,771 ms
コンパイル使用メモリ 76,800 KB
実行使用メモリ 55,924 KB
最終ジャッジ日時 2023-09-10 23:57:14
合計ジャッジ時間 5,700 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 119 ms
55,608 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 122 ms
55,916 KB
testcase_16 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        char c = 'w';
        while(s.charAt(0) == c){
            s = s.substring(1);
        }

        String maxans = "";
        int maxgrass = 0;

        String ans = "";
        int grass = 0;

        StringBuilder sb = new StringBuilder();
        boolean inStr = true; // true - constructing string, false - counting w
        
        for(int i = 0; i < s.length(); i++){
            if(inStr && s.charAt(i) != c){
                sb.append(s.charAt(i));
            }else if(inStr && s.charAt(i) == c){
                ans = sb.toString();
                sb.setLength(0);
                grass = 1;
                inStr = false;
            }else if(!inStr && s.charAt(i) == c){
                grass++;
            }else if(!inStr && s.charAt(i) != c){
                inStr = true;
                sb.setLength(0);
                sb.append(s.charAt(i));
                if(grass > maxgrass){
                    maxans = ans;
                    maxgrass = grass;
                }else if(grass == maxgrass){
                    maxans = maxans + "\n" + ans;
                }
                grass = 0;
                ans = "";
            }
        }

        if(!inStr){
            if(grass > maxgrass){
                maxans = ans;
            }else if(grass == maxgrass){
                maxans = maxans + "\n" + ans;
            }
        }

        System.out.print(maxans);
    }
}
0