結果

問題 No.2723 Fortune-telling by Flowers
ユーザー chro_96
提出日時 2024-04-12 22:30:00
言語 C
(gcc 13.3.0)
結果
AC  
実行時間 26 ms / 2,000 ms
コード長 700 bytes
コンパイル時間 206 ms
コンパイル使用メモリ 29,440 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-10-02 23:29:51
合計ジャッジ時間 1,017 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 13
権限があれば一括ダウンロードができます

ソースコード

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