Codeforces - Reverse-and-Concatenate

本文最後更新於:2024年1月12日 下午

Codeforces

出處 Codeforces Round 770 (Div. 2)
難度 800
標籤 greedy strings *800

Codeforces - Reverse-and-Concatenate

Reverse-and-Concatenate.cpp

// Author : ysh
// 02/06/2022 Sun 22:41:13.03
// https://codeforces.com/contest/1634/problem/A
#include<bits/stdc++.h>
using namespace std;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;cin>>n;
    while(n--) {
        int a,b;cin>>a>>b;
        string c;cin>>c;
        bool did = 0;
        if(b == 0) {
            cout<<1<<"\n";
            continue;
        }
        for(int i = 0;i<((a>>1)+1);i++) {
            if(c.at(i) != c.at(a - (i + 1))) {
                did = 1;
                cout<<2;
                break;
            }
        }
        if(did) cout<<"\n";
        else cout<<1<<"\n";
    }
    return 0;


    /*
    int n;cin>>n;
    string a;
    while(n--) {
        queue<string>f;
        queue<string>v;
        int b;cin>>b;
        cin>>a;
        f.push(a);
        while(b--) {
            while(!f.empty()) {
                auto now = f.front();f.pop();
                auto nnow=now;
                reverse(now.begin(),now.end());
            }
        }
    }
    */
}

Codeforces - Reverse-and-Concatenate
http://mysh212.github.io/algosolution/Reverse-and-Concatenate.cpp/
作者
ysh
發布於
2022年2月6日
更新於
2024年1月12日
許可協議