結果

問題 No.342 一番ワロタww
ユーザー kenji_shioyakenji_shioya
提出日時 2016-05-29 23:56:41
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,448 bytes
コンパイル時間 4,193 ms
コンパイル使用メモリ 78,460 KB
実行使用メモリ 41,716 KB
最終ジャッジ日時 2024-04-16 18:20:03
合計ジャッジ時間 6,555 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
41,500 KB
testcase_01 AC 128 ms
41,580 KB
testcase_02 AC 130 ms
41,396 KB
testcase_03 AC 127 ms
41,008 KB
testcase_04 AC 127 ms
41,448 KB
testcase_05 AC 130 ms
41,128 KB
testcase_06 AC 127 ms
41,232 KB
testcase_07 WA -
testcase_08 AC 115 ms
40,860 KB
testcase_09 AC 130 ms
41,396 KB
testcase_10 AC 131 ms
41,324 KB
testcase_11 AC 130 ms
41,688 KB
testcase_12 AC 130 ms
41,368 KB
testcase_13 AC 128 ms
41,328 KB
testcase_14 AC 129 ms
41,288 KB
testcase_15 AC 128 ms
41,180 KB
testcase_16 AC 130 ms
41,452 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

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

    Scanner sc = new Scanner(System.in);

    String str = sc.next();
    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