1027A. Palindromic Twist#变形回文串
题目内容:http://codeforces.com/contest/1027/problem/A
题目解析:输入T组字符串,每个字符串都必须改变一次,每个字母改变的规则是变成相邻的字母,字母a只能变b,z只能变y。改变后 的字符依旧是否能够变成回文串,就输出YES,否则就输出NO。注意,相邻的字母并没有固定是左边还右边,所以要考虑分成两种情况,一种本身就是回文串的就输出YES,不是回文串的判断对应位置字符asc码差是否等于2。
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int n,t,flag;
string s;
cin>>t;
while(t--)
{
flag=;
cin>>n>>s;
for(int i=; i<n/; i++)
if(s[i]!=s[n-i-]&&abs(s[i]-s[n-i-])!=)
{//用ascll码理解,满足:既不相等且相差非2
puts("NO");
flag=; break;
}
if(!flag)puts("YES");
}
return ;
}
参考出处:https://blog.csdn.net/memory_qianxiao/article/details/81838111
1027A. Palindromic Twist#变形回文串的更多相关文章
- Minimum Palindromic Factorization(最少回文串分割)
Minimum Palindromic Factorization(最少回文串分割) 以下内容大部分(可以说除了关于回文树的部分)来自论文A Subquadratic Algorithm for Mi ...
- [LeetCode] Longest Palindromic Substring 最长回文串
Given a string S, find the longest palindromic substring in S. You may assume that the maximum lengt ...
- Palindromic characteristics CodeForces - 835D (区间DP,预处理回文串问题)
Palindromic characteristics of string s with length |s| is a sequence of |s|integers, where k-th num ...
- 516. Longest Palindromic Subsequence最长的不连续回文串的长度
[抄题]: Given a string s, find the longest palindromic subsequence's length in s. You may assume that ...
- HDU5658:CA Loves Palindromic (回文树,求区间本质不同的回文串数)
CA loves strings, especially loves the palindrome strings. One day he gets a string, he wants to kno ...
- LightOJ - 1205:Palindromic Numbers (数位DP&回文串)
A palindromic number or numeral palindrome is a 'symmetrical' number like 16461 that remains the sam ...
- 《LeetBook》leetcode题解(5):Longest Palindromic [M]——回文串判断
我现在在做一个叫<leetbook>的免费开源书项目,力求提供最易懂的中文思路,目前把解题思路都同步更新到gitbook上了,需要的同学可以去看看 书的地址:https://hk029.g ...
- Leetcode0005--Longest Palindromic Substring 最长回文串
[转载请注明]http://www.cnblogs.com/igoslly/p/8726771.html 来看一下题目: Given a string s, find the longest pali ...
- PAT 甲级 1024 Palindromic Number (25 分)(大数加法,考虑这个数一开始是不是回文串)
1024 Palindromic Number (25 分) A number that will be the same when it is written forwards or backw ...
随机推荐
- ACM-牛喝水
题目描述:牛喝水 The cows have a line of 20 water bowls from which they drink. The bowls can be either righ ...
- win10 metasploit-framework 安装
1.metasploit.com官网下载.msi文件(可能下载速度会很慢) 2.安装时务必关闭Windows Defender及其他杀毒软件,并在安装完成后设置metasploit文件夹为白名单 wi ...
- 【剑指Offer】面试题10- I. 斐波那契数列
题目 写一个函数,输入 n ,求斐波那契(Fibonacci)数列的第 n 项.斐波那契数列的定义如下: F(0) = 0, F(1) = 1 F(N) = F(N - 1) + F(N - 2) ...
- POJ 2251 Dungeon Master(三维空间bfs)
题意:三维空间求最短路,可前后左右上下移动. 分析:开三维数组即可. #include<cstdio> #include<cstring> #include<queue& ...
- EUI库 - 9 - 数据集合 - 数据容器
DataGroup 设置一个数据源 自动创建内部所需的对象 来完成数据展示 还要设置单条数据的模板 叫ItemRenderer 继承关系 eui.List eui.ListBase e ...
- 汇编,寄存器,内存,mov指令
一.代码 和 汇编 和 二进制之间的关系 二.复习一下计算机组成原理的知识 1.寄存器 计算机中有三个存储 32位cpu提供的寄存器有三种类型8位 16位 32位 64位的只是32位的扩展 并且程序大 ...
- Python模块进阶、标准库、扩展库
模块进阶 Python有一套很有用的标准库(standard library).标准库会随着Python解释器,一起安装在你的电脑中的. 它是Python的一个组成部分.这些标准库是Python为你准 ...
- C#里的async和await的使用
1. await指令调起线程执行异步方法和方法内后面的代码 2. await指令会阻塞当前方法后面的代码,但是不会阻塞外部调用 3. await必须搭配async使用,而async不一定需要有awai ...
- poj_3461 KMP算法解析
A - Oulipo Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit S ...
- centos7 lvm合并分区脚本初探-linux性能测试 -centos7修改网卡名字-jdk环境安装脚本-关键字查询文件-批量添加用户
1.#!/bin/bash lvmdiskscan | grep centos > /root/a.txt a=`sed -n '1p' /root/a.txt` b=`sed -n '2p' ...