欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

Codeforces Round 932 (Div. 2)----->A. Entertainment in MAC

最编程 2024-03-11 06:59:59
...

一,思路:

简单的字符串处理,当反转字符串后如果字典序减小了,那么肯定不会再执行反转操作,而是执行操作2,将反转后的字符串拼接(这样必定构造一个回文串),那么之后的操作就没有任何意义了,因此看似有n个操作数,其实就两步操作。

二,代码:

#include <iostream>
#include<cstring>
#include<algorithm>
using namespace std;

void Solved(){
   int n;
   cin>>n;

   string str;
   cin>>str;

   str=min(str,string(str.rbegin(),str.rend())+str);

   cout<<str<<endl;

}

int main()
{
    int t;
    cin>>t;
    while(t--) {
        Solved();
    }
    return 0;
}