[CF#712Div2]A题Déjà Vu
作者:互联网
Pro
Sol
这个题不是很难 思路啥的也很好想 就说几个需要注意的地方吧
字符串切割分开输出的时候一定要注意substr的用法
分析什么时候可以输出NO是解题关键
其余都是一点调试就能找出来的小细节
官方题解
Code
#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
using namespace std;
typedef long long LL;
#define PI acos(-1)
#define INF 2147483647
#define eps 1e-7
#define L 100005
#define Fo(i,a,b) for(LL i=(a); i<=(b); i++)
#define Ro(i,b,a) for(LL i=(b); i>=(a); i--)
#define Ms(a,b) memset((a),(b),sizeof(a))
#define _ceil(_,__) (_+(__-1))/__
#define debug(_) cout<<endl<<"d::"<<_<<endl<<endl
#define type(_) typeid(_).name()
inline LL read() {
LL x = 0, f = 1;char c = getchar();
while (!isdigit(c)) { if (c == '-')f = -f;c = getchar(); }
while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48ll), c = getchar();
return x * f;
}
LL n;
string s;
int main() {
// freopen("data.txt","r",stdin);
n=read();
Fo(i,1,n) {
cin>>s;
LL len = s.size() , ff = 0;
Fo(j,0,len-1)
if(s[j]!='a') {
ff = 1;
break;
}
if(!ff) {
cout<<"NO"<<endl;
continue;
}
if(len%2) {
LL flag = 0;
Fo(j,0,len/2-1)
if(s[j]!=s[len-1-j]) {
flag = 1;
break;
}
if(!flag) {
cout<<"YES"<<endl<<"a"<<s<<endl;
} else {
Fo(j,0,len-1)
if(s[j]!='a') {
cout<<"YES"<<endl<<s.substr(0,len-j)<<"a"<<s.substr(len-j,len)<<endl;
break;
}
}
} else {
LL flag = 0;
Fo(j,0,len/2-1)
if(s[j]!=s[len-1-j]) {
flag = 1;
break;
}
if(!flag)
cout<<"YES"<<endl<<"a"<<s<<endl;
else
Fo(j,0,len-1)
if(s[j]!='a') {
cout<<"YES"<<endl<<s.substr(0,len-j)<<"a"<<s.substr(len-j,len)<<endl;
break;
}
}
}
return 0;
}
标签:cout,712Div2,LL,CF,len,flag,Vu,include,define 来源: https://blog.csdn.net/cls1277/article/details/115442359