結果

問題 No.418 ミンミンゼミ
ユーザー nihi9119nihi9119
提出日時 2017-05-29 18:04:33
言語 Java21
(openjdk 21)
結果
AC  
実行時間 41 ms / 1,000 ms
コード長 1,715 bytes
コンパイル時間 3,234 ms
コンパイル使用メモリ 71,956 KB
実行使用メモリ 49,752 KB
最終ジャッジ日時 2023-09-23 01:52:51
合計ジャッジ時間 5,009 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
49,116 KB
testcase_01 AC 39 ms
49,308 KB
testcase_02 AC 40 ms
49,600 KB
testcase_03 AC 40 ms
49,408 KB
testcase_04 AC 40 ms
49,072 KB
testcase_05 AC 40 ms
49,296 KB
testcase_06 AC 39 ms
49,752 KB
testcase_07 AC 39 ms
49,048 KB
testcase_08 AC 41 ms
49,064 KB
testcase_09 AC 41 ms
49,484 KB
testcase_10 AC 40 ms
49,204 KB
testcase_11 AC 40 ms
49,288 KB
testcase_12 AC 39 ms
49,120 KB
testcase_13 AC 39 ms
49,680 KB
testcase_14 AC 41 ms
49,176 KB
testcase_15 AC 40 ms
49,580 KB
testcase_16 AC 39 ms
49,112 KB
testcase_17 AC 40 ms
49,076 KB
testcase_18 AC 39 ms
49,352 KB
testcase_19 AC 40 ms
49,140 KB
testcase_20 AC 40 ms
49,528 KB
testcase_21 AC 40 ms
49,216 KB
testcase_22 AC 40 ms
49,208 KB
testcase_23 AC 40 ms
49,192 KB
testcase_24 AC 40 ms
49,264 KB
testcase_25 AC 40 ms
49,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package test_5;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/*No.418 ミンミンゼミ
*
* - まず "mi" から始まる。
* - その後いくつかの "-" がつく。"-" の数は 0 でもかまわない。
* - 最後に "n" で終わる。
* あなたの仕事は, 文字列 SS がいくつのミーン文字列を繰り返しているかを数えることです。
* */

public class Question_05_0526_2 {

	static final int MIN_LENGTH = 3;
	static final int MAX_LENGTH = 100;
	static final char LAST_CHARACTER = 'n';

	public static void main(String[] args) {

		InputStreamReader re = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(re);

		try {

			int minCount = 0;
			String minString = br.readLine();

			if (NumJudgment(minString)) {

				for (char c : minString.toCharArray()) {
					if (c == LAST_CHARACTER) {
						minCount++;
					}
				}

				// セミが何回「ミーン」と鳴いたかを出力
				System.out.println(minCount);

			} else {
				System.out.println("桁数が不正です");
			}

		} catch (IOException e) {
			System.out.println("エラーが発生しました");
		} finally {
			try {
				re.close();
				br.close();
			} catch (IOException e) {
				System.out.println("InputStreamReader、BufferedReaderクローズ中にエラーが発生しました");
			}
		}
	}

	/**
	 * 有効値判定メソッド
	 *
	 * @param minString
	 * @return true:問題なし、false:エラー
	 */
	private static boolean NumJudgment(String minString) {
		Boolean result = false;
		if (MIN_LENGTH <= minString.length() && minString.length() <= MAX_LENGTH) {
			result = true;
		}
		return result;
	}

}
0