結果
問題 | No.486 3 Straight Win(3連勝) |
ユーザー |
|
提出日時 | 2017-06-09 09:42:54 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 62 ms / 2,000 ms |
コード長 | 2,366 bytes |
コンパイル時間 | 3,457 ms |
コンパイル使用メモリ | 77,796 KB |
実行使用メモリ | 50,448 KB |
最終ジャッジ日時 | 2024-06-26 04:29:04 |
合計ジャッジ時間 | 6,074 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 28 |
ソースコード
package test6;import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;/*** No.486 3 Straight Win(3連勝) http://yukicoder.me/problems/no/486* 東軍と西軍はあるゲームで勝負しています。* そのゲームは東軍と西軍のどちらか一方が必ず勝ちもう一方は必ず負けます。* 両軍はそのゲームを何度か繰り返し、先に3連勝した方をこのゲームの最終的な勝者にしようと取り決めました。*/public class Question_17_0609 {static final int MIN = 1;static final int MAX = 100;static final String EAST_WIN = "OOO"; //東軍の勝利static final String WEST_WIN = "XXX"; //西軍の勝利public static void main(String[] args) {InputStreamReader re = new InputStreamReader(System.in);BufferedReader br = new BufferedReader(re);try {String input = br.readLine();if (LengthJudg(input, MIN, MAX)) {//最初に三連勝した場所を数えるint east = input.indexOf(EAST_WIN);int west = input.indexOf(WEST_WIN);String result = "";//勝利判定//両者とも3連勝していないif (east == west) {result = "NA";//東軍が3連勝していない、または//西軍が3連勝し、かつ西軍の方が3連勝が早かった場合} else if (east == -1 || (west != -1 && Math.min(east, west) == west)) {result = "West";} else {result = "East";}System.out.println(result);} else {System.out.println("入力文字の長さが有効範囲外です");}} catch (NumberFormatException e) {System.out.println("数字を入力して下さい。");} catch (IOException e) {System.out.println("エラーが発生しました。");} finally {try {re.close();br.close();} catch (IOException e) {System.out.println("InputStreamReader、BufferedReaderクローズ中にエラーが発生しました");}}}/*** 有効値判定* @param input 判定するもの* @param max 最大値* @param min 最小値* @return 範囲内ならtrue,範囲外ならfalseを返す*/private static boolean LengthJudg(String input, int min, int max) {Boolean result = false;if (min <= input.length() && input.length() <= max) {result = true;}return result;}}