結果

問題 No.2723 Fortune-telling by Flowers
ユーザー ks2mks2m
提出日時 2024-04-12 22:01:20
言語 Java21
(openjdk 21)
結果
AC  
実行時間 266 ms / 2,000 ms
コード長 681 bytes
コンパイル時間 2,346 ms
コンパイル使用メモリ 74,832 KB
実行使用メモリ 57,960 KB
最終ジャッジ日時 2024-04-12 22:01:26
合計ジャッジ時間 5,793 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 56 ms
50,340 KB
testcase_01 AC 107 ms
52,552 KB
testcase_02 AC 179 ms
57,960 KB
testcase_03 AC 245 ms
56,064 KB
testcase_04 AC 266 ms
57,784 KB
testcase_05 AC 120 ms
53,912 KB
testcase_06 AC 125 ms
53,784 KB
testcase_07 AC 131 ms
54,032 KB
testcase_08 AC 174 ms
53,868 KB
testcase_09 AC 189 ms
57,048 KB
testcase_10 AC 158 ms
53,336 KB
testcase_11 AC 145 ms
55,672 KB
testcase_12 AC 125 ms
53,996 KB
testcase_13 AC 133 ms
54,060 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int t = Integer.parseInt(br.readLine());
		PrintWriter pw = new PrintWriter(System.out);
		for (int z = 0; z < t; z++) {
			int n = Integer.parseInt(br.readLine());
			char[] s = br.readLine().toCharArray();

			int k = 0;
			int p = 0;
			char pre = 'a';
			for (int i = 0; i < n; i++) {
				if (s[i] != pre) {
					if (s[i] =='K') k++;
					if (s[i] =='P') p++;
					pre = s[i];
				}
			}
			if (k >= p) {
				pw.println("K");
			} else {
				pw.println("P");
			}
		}
		pw.flush();
		br.close();
	}
}
0