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 ...
随机推荐
- SpringMVC的映射器、适配器、解析器
1.处理器和适配器 1.1springmvc的映射器 根据客户端请求的url,找到处理本次请求的handler(处理器),将url和controller关联起来 1.2springmvc的适配器 对映 ...
- IntelliJ IDEA 教程(1)
过完年,新的学习阶段又开始了.星爷的电影票还没还,国民岳父(韩寒)的礼钱也没送,王老板说再立一个小目标,马老板说我不在乎钱...学习还得继续. IntelliJ Idea 简称IDEA,是java语言 ...
- 【转】Java中super和this的几种用法与区别
1. 子类的构造函数如果要引用super的话,必须把super放在函数的首位. class Base { Base() { System.out.println("Base&qu ...
- 详解css3弹性盒模型(Flexbox)
目前没有浏览器支持 box-flex 属性. Firefox 支持替代的 -moz-box-flex 属性. Safari.Opera 以及 Chrome 支持替代的 -webkit-box-flex ...
- TagHelper+Layui封装组件之Radio单选框
TagHelper+Layui封装组件之Radio单选框 标签名称:cl-radio 标签属性: asp-for:绑定的字段,必须指定 asp-items:绑定单选项 类型为:IEnumerable& ...
- lodash源码分析之缓存方式的选择
每个人心里都有一团火,路过的人只看到烟. --<至爱梵高·星空之谜> 本文为读 lodash 源码的第八篇,后续文章会更新到这个仓库中,欢迎 star:pocket-lodash gitb ...
- Can you find it?(哈希)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=2141 Can you find it? Time Limit: 10000/3000 MS (Java ...
- c++(数据选择)
在数学中,有一些数据选择的内容.举个例子来说,有这样一组数据:1.2.3.4.现在我们打算从中挑选出1个数据,那么有几种选择呢?结果应该是1.2.3.4:那么如果挑选2个数据呢,怎么选呢?那么结果应该 ...
- C#的改进特性
1.初始器 当你新建一个对象实例的时候,是否遇到下面这种情况: class a = new class(); a.item1 = "; a.item2 = "; 或者写一个构造函数 ...
- [国嵌攻略][142][LCD驱动程序架构]
LCD裸机驱动回顾 1.LCD初始化 1.1.控制器初始化 1.2.端口初始化 1.3.指明了帧缓冲 2.LCD图形显示 2.1.将图形数据写入帧缓冲 Linux帧缓冲体验 把图片转换成开发板屏对应的 ...