結果

問題 No.342 一番ワロタww
ユーザー kenji_shioyakenji_shioya
提出日時 2016-05-30 00:26:58
言語 Java21
(openjdk 21)
結果
AC  
実行時間 53 ms / 5,000 ms
コード長 2,538 bytes
コンパイル時間 3,739 ms
コンパイル使用メモリ 78,520 KB
実行使用メモリ 37,460 KB
最終ジャッジ日時 2024-04-23 13:25:25
合計ジャッジ時間 4,600 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 49 ms
36,752 KB
testcase_01 AC 50 ms
36,984 KB
testcase_02 AC 50 ms
37,460 KB
testcase_03 AC 50 ms
37,256 KB
testcase_04 AC 51 ms
37,180 KB
testcase_05 AC 48 ms
37,256 KB
testcase_06 AC 48 ms
37,256 KB
testcase_07 AC 51 ms
37,140 KB
testcase_08 AC 49 ms
37,072 KB
testcase_09 AC 50 ms
37,128 KB
testcase_10 AC 50 ms
37,444 KB
testcase_11 AC 51 ms
37,076 KB
testcase_12 AC 51 ms
37,412 KB
testcase_13 AC 51 ms
37,224 KB
testcase_14 AC 50 ms
37,204 KB
testcase_15 AC 50 ms
37,000 KB
testcase_16 AC 53 ms
37,340 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

public class Exercise33{
  public static void main (String[] args) throws IOException{

    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String str = new String(in.readLine());

    char[] charArray = str.toCharArray();

    ArrayList<ResultStr> strList = new ArrayList<ResultStr>();

    boolean preW = false;
    boolean getChar = false;
    boolean empty = true;

    int wCount = 0;
    int maxW = 0;

    for (int n = charArray.length - 1; n >= 0; n--){
      // wは全角注意
      if (charArray[n] == 'w'){
        if (preW){
          wCount++;
        }else{
          preW = true;
          wCount++;
        }

        if (getChar){
          getChar = false;
        }
      // w以外の文字の時
      }else{
        // 候補1文字目
        if(preW){
          // Wcountをmaxと比較
          maxW = Math.max(wCount, maxW);
          if (wCount == maxW){
            getChar = true;
            // すでに候補がなければ
            if (strList.isEmpty()){
              ResultStr newStr = new ResultStr(wCount);
              strList.add(0, newStr);
            // あれば
            }else{
              ResultStr resultStr = strList.get(0);
              if (wCount > resultStr.numOfW){
                strList.clear();
                ResultStr newStr = new ResultStr(wCount);
                strList.add(0, newStr);
              }else if(wCount == resultStr.numOfW){
                ResultStr newStr = new ResultStr(wCount);
                strList.add(0, newStr);
              }
            }
          }
          preW = false;
          wCount = 0;
        }
        // 候補1文字目終わり
        // 2文字目以降
        if (getChar){
          ResultStr resultStr = strList.get(0);
          resultStr.push(charArray[n]);
        }
      }
    }

    for (int j = 0; j < strList.size(); j++){
      ResultStr resultStr = strList.get(j);
      char[] answerArray = new char[resultStr.strArray.size()];
      for (int a = 0; a < resultStr.strArray.size(); a++){
        answerArray[a] = resultStr.strArray.get(a);
      }
      String answer = String.valueOf(answerArray);
      System.out.println(answer);
      empty = false;
    }

    if(empty){
      System.out.println("");
    }
  }
}

class ResultStr {
  int numOfW;
  LinkedList<Character> strArray;

  ResultStr(int num) {
    numOfW = num;
    strArray = new LinkedList<Character>();
  }

  void push(char chars){
    strArray.push(chars);
  }
}
0