Codeforce A. Quasi-palindrome
1 second
256 megabytes
standard input
standard output
Let quasi-palindromic number be such number that adding some leading zeros (possible none) to it produces a palindromic string.
String t is called a palindrome, if it reads the same from left to right and from right to left.
For example, numbers 131 and 2010200 are quasi-palindromic, they can be transformed to strings "131" and "002010200", respectively, which are palindromes.
You are given some integer number x. Check if it's a quasi-palindromic number.
The first line contains one integer number x (1 ≤ x ≤ 109). This number is given without any leading zeroes.
Print "YES" if number x is quasi-palindromic. Otherwise, print "NO" (without quotes).
131
YES
320
NO
2010200
YES 这题代码题;
枚举每个中间点就行了;
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
using namespace std; char s[],flag; int main(){
scanf("%s",s);
flag=-;
int len=strlen(s);
for(int i=len-;i>=;i--)
if(s[i]!=''){
flag=i;
break;
}
for(int i=;i<len;i++){
int x=;
while(i-x>=&&i+x<len&&s[i-x]==s[i+x]){
x++;
}
if(i+x>flag&&i-x<){
printf("YES");
return ;
}
}
for(int i=;i<len;i++){
int x=i,y=i+;
while(x>=&&y<len&&s[x]==s[y]){
x--; y++;
}
if(y>flag&&x<){
printf("YES");
return ;
}
}
printf("NO");
}
Codeforce A. Quasi-palindrome的更多相关文章
- codeforce 600C - Make Palindrome
练习string 最小变换次数下,且字典序最小输出回文串. #include <cstdio> #include <cstring> #include <cmath> ...
- PALIN - The Next Palindrome 对称的数
A positive integer is called a palindrome if its representation in the decimal system is the same wh ...
- [LeetCode] Longest Palindrome 最长回文串
Given a string which consists of lowercase or uppercase letters, find the length of the longest pali ...
- [LeetCode] Palindrome Pairs 回文对
Given a list of unique words. Find all pairs of distinct indices (i, j) in the given list, so that t ...
- [LeetCode] Palindrome Permutation II 回文全排列之二
Given a string s, return all the palindromic permutations (without duplicates) of it. Return an empt ...
- [LeetCode] Palindrome Permutation 回文全排列
Given a string, determine if a permutation of the string could form a palindrome. For example," ...
- [LeetCode] Palindrome Linked List 回文链表
Given a singly linked list, determine if it is a palindrome. Follow up: Could you do it in O(n) time ...
- [LeetCode] Shortest Palindrome 最短回文串
Given a string S, you are allowed to convert it to a palindrome by adding characters in front of it. ...
- [LeetCode] Palindrome Partitioning II 拆分回文串之二
Given a string s, partition s such that every substring of the partition is a palindrome. Return the ...
- [LeetCode] Palindrome Partitioning 拆分回文串
Given a string s, partition s such that every substring of the partition is a palindrome. Return all ...
随机推荐
- Python3 决策树
# -*- coding: utf-8 -*-"""Created on Fri Dec 29 10:18:04 2017 @author: markli"&q ...
- (亲测)1分钟破解IDM权限,傻瓜都能学会的破解方法(番外篇:利用破解工具直接破解IDM)
Internet Download Manager (IDM)是比较好用的一款下载工具~ 上一节我讲到一种利用修改防火墙来进行阻止访问服务器,请参看这篇文章(亲测)躺着破解IDM下载权限,治疗不用破解 ...
- 让两个数x,y一直保持互质的模版
int gcd(int x,int y) { )return x; else return gcd(y,x%y); }
- 搭建vue开发环境的步骤
相信很多人在刚开始学习vue这个框架的时候,在最开始搭建开发环境的时候,都会遇到一些大大小小的坑,我之前在学习angular的时候搭建过一次,过了一个月后在搭建第二次的时候,竟然有一些混乱,所以今天想 ...
- Flexbox 练习和总结
练习地址: http://flexboxfroggy.com/ Welcome to Flexbox Froggy, a game where you help Froggy and friends ...
- C语言单向链表
1,为什么要用到链表 数组作为存放同类数据的集合,给我们在程序设计时带来很多的方便,增加了灵活性.但数组也同样存在一些弊病.如数组的大小在定义时要事先规定,不能在程序中进行调整,这样一来,在程序设计中 ...
- 使用 SVG 和 JS 创建一个由星形变心形的动画
序言:首先,这是一篇学习 SVG 及 JS 动画不可多得的优秀文章.我非常喜欢 Ana Tudor 写的教程.在她的教程中有大量使用 SVG 制作的图解以及实时交互 DEMO,可以说教程的所有细枝末节 ...
- angular2 Http和websocket
1. 注入HttpModule模块: 2. 注入http服务 map方法需要导入"rajx/Rx"组件,作用是针对流的处理.Json是将流转化为json格式.subscribe订阅 ...
- 解决sql和beans中名字不一致问题
第二图使用别名 tid为sql中的名字,id为beans中的名字,推荐此方式
- 语义化版本控制规范(SemVer)
摘自: http://semver.org/lang/zh-CN/ 简介 在软件管理的领域里存在着被称作"依赖地狱"的死亡之谷,系统规模越大,加入的套件越多,你就越有可能在未来的某 ...