結果

問題 No.2723 Fortune-telling by Flowers
コンテスト
ユーザー chro_96
提出日時 2024-04-12 22:30:00
言語 C(gnu17)
(gcc 15.2.0)
コンパイル:
gcc-15 -O2 -std=gnu17 -Wno-error=implicit-function-declaration -Wno-error=implicit-int -Wno-error=incompatible-pointer-types -Wno-error=int-conversion -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
AC  
実行時間 23 ms / 2,000 ms
コード長 700 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 154 ms
コンパイル使用メモリ 38,208 KB
最終ジャッジ日時 2026-02-22 11:39:38
ジャッジサーバーID
(参考情報)
judge2 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 13
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#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