結果

問題 No.2723 Fortune-telling by Flowers
ユーザー 👑 chro_96chro_96
提出日時 2024-04-12 22:30:00
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 25 ms / 2,000 ms
コード長 700 bytes
コンパイル時間 301 ms
コンパイル使用メモリ 30,208 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-12 22:30:02
合計ジャッジ時間 1,564 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 3 ms
6,816 KB
testcase_02 AC 10 ms
6,940 KB
testcase_03 AC 19 ms
6,940 KB
testcase_04 AC 25 ms
6,944 KB
testcase_05 AC 4 ms
6,940 KB
testcase_06 AC 7 ms
6,940 KB
testcase_07 AC 8 ms
6,940 KB
testcase_08 AC 8 ms
6,940 KB
testcase_09 AC 10 ms
6,944 KB
testcase_10 AC 8 ms
6,940 KB
testcase_11 AC 8 ms
6,940 KB
testcase_12 AC 8 ms
6,940 KB
testcase_13 AC 8 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

int main () {
  int t = 0;
  int n = 0;
  char s[500001] = "";
  
  int res = 0;
  
  res = scanf("%d", &t);
  while (t > 0) {
    int cnt[2] = {};
    res = scanf("%d", &n);
    res = scanf("%s", s);
    for (int i = 0; i < n; i++) {
      if (s[i] == 'P' && (i <= 0 || s[i-1] == '-')) {
        cnt[0]++;
      } else if (s[i] == 'K' && (i <= 0 || s[i-1] == '-')) {
        cnt[1]++;
      }
      if (s[i] == 'P' && (i >= n-1 || s[i+1] == '-')) {
        cnt[0]++;
      } else if (s[i] == 'K' && (i >= n-1 || s[i+1] == '-')) {
        cnt[1]++;
      }
    }
    if (cnt[0] > cnt[1]) {
      printf("P\n");
    } else {
      printf("K\n");
    }
    t--;
  }
  
  return 0;
}
0