CodeForces 1935A

薛定谔的AC發表於2024-06-16

題目連結:Entertainment in MAC



思路


程式碼

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e5 + 10;


void solve() {
    ll n;
    string s;
    cin >> n >> s;
    int l = 0, len = s.size();
    while (s[l] == s[len - 1 - l] && l < len / 2) {
        l++;
    }
    if (s[l] > s[len - l - 1]) {
        if (n % 2) {
            reverse(s.begin(), s.end());
        }
        else {
            string auxious = s;
            reverse(s.begin(), s.end());
            s = s + auxious;
        }
    }
    else if (s[l] < s[len - 1 - l]){
        if (n % 2) {
            string auxious = s;
            reverse(s.begin(), s.end());
            s = auxious + s;
        }
    }
    cout << s << endl;
}
int main(){
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

相關文章