結果

問題 No.2723 Fortune-telling by Flowers
ユーザー MasKoaTSMasKoaTS
提出日時 2023-12-21 01:58:11
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 177 ms / 2,000 ms
コード長 904 bytes
コンパイル時間 2,218 ms
コンパイル使用メモリ 206,132 KB
実行使用メモリ 9,788 KB
最終ジャッジ日時 2023-12-21 13:57:26
合計ジャッジ時間 3,683 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 8 ms
6,676 KB
testcase_02 AC 38 ms
6,676 KB
testcase_03 AC 161 ms
6,676 KB
testcase_04 AC 177 ms
6,676 KB
testcase_05 AC 13 ms
6,676 KB
testcase_06 AC 14 ms
6,676 KB
testcase_07 AC 22 ms
9,788 KB
testcase_08 AC 22 ms
9,788 KB
testcase_09 AC 38 ms
6,676 KB
testcase_10 AC 20 ms
6,676 KB
testcase_11 AC 19 ms
6,676 KB
testcase_12 AC 20 ms
6,676 KB
testcase_13 AC 23 ms
8,136 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

vector<string> split(const string &s, char delim) {
    vector<string> ret;
    string tmp;
    for(char c : s){
        if(c == delim){
            if(!tmp.empty()){
                ret.push_back(tmp);
            }
            tmp.clear();
        }
        else {
            tmp.push_back(c);
        }
    }
    if(!tmp.empty()){
        ret.push_back(tmp);
    }
    return ret;
}


char solve(int n, string& s){
    vector<string> vec = split(s, '-');
    int score = 0;
    for(string& ss : vec){
        score += (ss[0] == 'K' || ss[ss.size() - 1] == 'K');
        score -= (ss[0] == 'P' || ss[ss.size() - 1] == 'P');
    }
    return (score >= 0) ? 'K' : 'P';
}


int main(){
    int t;  cin >> t;

    for(int i = 0; i < t; ++i){
        int n;  cin >> n;
        string s;   cin >> s;
        cout << solve(n, s) << endl;
    }

    return 0;
}
0