結果

問題 No.418 ミンミンゼミ
ユーザー nihi9119nihi9119
提出日時 2017-05-25 21:08:13
言語 Java21
(openjdk 21)
結果
AC  
実行時間 46 ms / 1,000 ms
コード長 2,350 bytes
コンパイル時間 3,982 ms
コンパイル使用メモリ 77,748 KB
実行使用メモリ 50,152 KB
最終ジャッジ日時 2023-09-23 01:51:46
合計ジャッジ時間 5,951 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
49,724 KB
testcase_01 AC 44 ms
49,788 KB
testcase_02 AC 45 ms
49,756 KB
testcase_03 AC 46 ms
49,764 KB
testcase_04 AC 45 ms
49,608 KB
testcase_05 AC 44 ms
49,768 KB
testcase_06 AC 46 ms
49,984 KB
testcase_07 AC 44 ms
49,812 KB
testcase_08 AC 44 ms
49,764 KB
testcase_09 AC 45 ms
49,784 KB
testcase_10 AC 45 ms
50,108 KB
testcase_11 AC 45 ms
49,684 KB
testcase_12 AC 46 ms
49,784 KB
testcase_13 AC 45 ms
50,108 KB
testcase_14 AC 44 ms
49,968 KB
testcase_15 AC 46 ms
49,676 KB
testcase_16 AC 44 ms
49,852 KB
testcase_17 AC 44 ms
49,676 KB
testcase_18 AC 45 ms
49,956 KB
testcase_19 AC 45 ms
49,764 KB
testcase_20 AC 44 ms
49,832 KB
testcase_21 AC 45 ms
49,880 KB
testcase_22 AC 45 ms
49,776 KB
testcase_23 AC 46 ms
49,768 KB
testcase_24 AC 46 ms
50,152 KB
testcase_25 AC 46 ms
49,868 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_0525_1 {

	static final int MIN_LENGTH = 3;
	static final int MAX_LENGTH = 100;
	static final String FIRST_CHARACTER = "mi";
	static final String LAST_CHARACTER = "n";

	public static void main(String[] args) {

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

		try {

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

			if (NumJudgment(minString)) {

				String[] minArray = minString.split("");

				do {
					for (int i = StringCount; i < minArray.length; i++) {
						// minを探す
						twoCharacter = minArray[i] + minArray[i + 1];
						if (twoCharacter.equals(FIRST_CHARACTER)) {
							StringCount = i + 2; //miの2文字分進める
							// nを探す
							for (int j = StringCount; j < minArray.length; j++) {
								if (minArray[j].equals(LAST_CHARACTER)) {
									StringCount = j + 1; //nの次から検索を始める
									minCount++;
									break;
								}
							}
							break;
						}
						// miがなければループ
						else {
							StringCount = i + 2;//miの2文字分進める
						}
					}
				} while (StringCount < minString.length());

				// セミが何回「ミーン」と鳴いたかを出力
				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クローズ中にエラーが発生しました");
			}
		}
	}

	// 有効値判定メソッド
	private static boolean NumJudgment(String minString) {
		Boolean result = false;
		if (MIN_LENGTH <= minString.length() && minString.length() <= MAX_LENGTH) {
			result = true;
		}
		return result;
	}

}
0