A palindrome is a string that reads the same backward as forward. For example, the strings “z”, “aaa”, “aba”, and “abccba” are palindromes, but “codeforces” and “ab” are not. You hate palindromes because they give you déjà vu.

There is a string s. You must insert exactly one character ‘a’ somewhere in s. If it is possible to create a string that is not a palindrome, you should find one example. Otherwise, you should report that it is impossible.

For example, suppose s= “cbabc”. By inserting an ‘a’, you can create “acbabc”, “cababc”, “cbaabc”, “cbabac”, or “cbabca”. However “cbaabc” is a palindrome, so you must output one of the other options.

Input
The first line contains a single integer t (1≤t≤104) — the number of test cases.

The only line of each test case contains a string s consisting of lowercase English letters.

The total length of all strings does not exceed 3⋅105.

Output
For each test case, if there is no solution, output “NO”.

Otherwise, output “YES” followed by your constructed string of length |s|+1 on the next line. If there are multiple solutions, you may print any.

You can print each letter of “YES” and “NO” in any case (upper or lower).

input
6
cbabc
ab
zza
ba
a
nutforajaroftuna
output
YES
cbabac
YES
aab
YES
zaza
YES
baa
NO
YES
nutforajarofatuna

My Answer Code:

/*Author:Albert Tesla WizardTime:2021/4/5 23:43
*/
#include<bits/stdc++.h>
using namespace std;
bool dc(string s)
{int len=s.length();bool flag=true;for(int i=0;i<len/2;i++){if(s[i]!=s[len-1-i]){flag=false;break;}}return flag;
}
void solve(string s)
{int len=s.length();bool flag=false;for(int i=0;i<len;i++){if(s[i]!='a'){flag=true;break;}}if(!flag)cout<<"NO"<<'\n';else{if(dc(s)){cout<<"YES"<<'\n';cout<<"a"+s<<'\n';}else{int len=s.length();string s1=s.insert(len/2,1,'a');cout<<"YES"<<'\n';cout<<s1<<'\n';}}
}
int main()
{ios::sync_with_stdio(false);cin.tie(0);int t;cin>>t;while(t--){string s;cin>>s;solve(s);}return 0;
}

A. Déjà Vu相关推荐

  1. 陀螺年度好文回顾|「The DeFi Déjà Vu」——万字长文剖析DeFi困局

    来源:预见家Foreseer 文/蒋新 本文始发于2019年8月25日 2019,区块链行业在混沌中探索前进,但对于从业者来说2019无疑是里程碑式的一年. 回顾2019年,中国区块链行业的发展经历了 ...

  2. 确认!语音识别大牛Daniel Povey将入职小米,曾遭霍普金斯大学解雇,怒拒Facebook

    整理 | 夕颜 出品 | AI科技大本营(ID:rgznai100) [导读]10 月 17 日,语音界传奇 Daniel  Povey 发布推特,宣布自己 2019 年末将要入职小米,目前正在签订合 ...

  3. Codeforces Round #712 Div.2(A ~ F) 超高质量题解(每日训练 Day.15 )

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #712 Div.2(A ~ F) 题解 比赛链接:https:// ...

  4. 走向通用智能的核心:任务树的建立

    来源:混沌巡洋舰 人工智能的一个核心问题,是用已有的算法解决新的目标.对于人类来说,最常用的方法是得到和目标最相近的子目标, 子目标的子目标(比如饿了就要找吃的,找吃的就要去菜市场买菜),直到和当下的 ...

  5. WWW2020推荐系统论文合集(已分类整理,并提供下载)

    文章来源于机器学习与推荐算法,作者张小磊 1   摘要 国际顶级学术会议WWW2020定在2020年4月20-24日于中国台湾举办.受COVID-19疫情影响(疫情赶紧过去吧),大会将在线上举行.今天 ...

  6. Codeforces Round #712 (Div. 2)

    题号 题目 知识点 质量 1504A Déjà Vu 思维题 1504B Flip the Bits 贪心 1504C Balance the Bits 构造题 1504D 3-Coloring 思维 ...

  7. codeforces:ProblemMset

    最近一个月在codeforces上做的题(做个记录) 后面太多了就不把代码一一放出了,只放置了链接,可根据链接找到提交的代码. 最小子矩阵 #include <iostream> #inc ...

  8. 动词的时态(Les temps du verbe )

    在开始讲解直陈式现在时的主要用法之前,我们有必要先搞清楚两个基本概念: ▶语式(mode):语式是动词表达动作的方式.一个动作,可以作为实在的事表达出来,也可以作为希望或单纯设想的事表达出来,法语动词 ...

  9. CCS2020论文泛读记录

    写在前面 CCS '20: Proceedings of the 2020 ACM SIGSAC Conference on Computer and Communications Security ...

最新文章

  1. 程序员的周末:纯野的一天
  2. RealARM 210开发板 u-boot传递mac地址到内核的方法
  3. lombok不生效问题(持续补充)
  4. JS的常用正则表达式 验证密码
  5. C/C++:Windows编程—Inline Hook内联钩子(上)
  6. Luogu P2066 机器分配(dp)
  7. 机器学习-吴恩达-笔记-10-降维
  8. Python菜鸟入门:day11文件操作
  9. kvm虚拟机设置万兆网卡_kvm已经设置桥接网卡的虚拟机无法连接宿主机?
  10. selenium 自动化web测试
  11. 微信小程序chooseMedia应用
  12. 蓝牙音乐之A2DP音频流
  13. 手把手教你建立私人数据检索库(二)
  14. php表格好看样式,怎么用css制作好看的表格?【示例】
  15. 双11中奖名单公布啦
  16. lol祖安服务器维护,触目惊心 被演员与代练所“支配”的英雄联盟
  17. TCP/IP详解:卷1
  18. 一对一 视频聊天源码,不要小瞧社交平台的盈利方式
  19. Groovy 和 Java 联合开发环境搭建
  20. 算法导论第八章思考题

热门文章

  1. 分布式事务之Seata个人吐血整理
  2. 2021年全球汽车天线收入大约1816.1百万美元,预计2028年达到2199.7百万美元,2022至2028期间,年复合增长率CAGR为3.0%
  3. 已知坐标用matlab画图,已知45个点X Y Z的坐标值已知,如何用matlab画出网格图,每......
  4. 003@ uboot第二阶段分析(下)
  5. PageRank 笔记
  6. UART串口流控制(Flow control)
  7. Cortex-M系列的优劣对比
  8. ASP.NET Core 托管和部署(一)【Kestrel】
  9. 2011RTIC论坛回顾
  10. 算法4 Java解答 2.4.18