水题:P2799 国王的魔镜
思路:简单模拟即可。判断一下是不是回文,是回文看长度是不是偶数。是偶数的话,说明又可能是回文。依次这样处理。但是只要长度为奇数则一定是原来的长度直接输出即可。
#include<iostream>
#include<cstring>
using namespace std; const int maxn = + ;
char num[maxn]; bool flag(int x){
int p = , q = x-;
while (p < q&&num[p] == num[q]){ ++p; --q; }
if (p < q)return ;
return ;
} int main(){
cin >> num;
int len = strlen(num);
if (len % ){ cout << len << endl; return ; }
while (len / ){
if (flag(len))len /= ;
else break;
if (len % )break;
}
cout << len << endl;
}
水题:P2799 国王的魔镜的更多相关文章
- 洛谷——P2799 国王的魔镜
P2799 国王的魔镜 题目描述 国王有一个魔镜,可以把任何接触镜面的东西变成原来的两倍——只是,因为是镜子嘛,增加的那部分是反的.比如一条项链,我们用AB来表示,不同的字母表示不同颜色的珍珠.如果把 ...
- 洛谷 P2799 国王的魔镜
把项链当做字符串输进去,可以用gets #include<iostream>#include<cstdio>#include<cmath>#include<c ...
- P2799国王的魔镜
链接 想了好久(蒟蒻的不能蒟蒻) 题解: #include<iostream>#include<cstdio>#include<cstring>#include&l ...
- 【BZOJ】3850: ZCC Loves Codefires(300T就这样献给了水题TAT)
http://www.lydsy.com/JudgeOnline/problem.php?id=3850 题意:类似国王游戏....无意义.. #include <cstdio> #inc ...
- HDOJ 2317. Nasty Hacks 模拟水题
Nasty Hacks Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tota ...
- ACM :漫漫上学路 -DP -水题
CSU 1772 漫漫上学路 Time Limit: 1000MS Memory Limit: 131072KB 64bit IO Format: %lld & %llu Submit ...
- ytu 1050:写一个函数,使给定的一个二维数组(3×3)转置,即行列互换(水题)
1050: 写一个函数,使给定的一个二维数组(3×3)转置,即行列互换 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 154 Solved: 112[ ...
- [poj2247] Humble Numbers (DP水题)
DP 水题 Description A number whose only prime factors are 2,3,5 or 7 is called a humble number. The se ...
- gdutcode 1195: 相信我这是水题 GDUT中有个风云人物pigofzhou,是冰点奇迹队的主代码手,
1195: 相信我这是水题 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 821 Solved: 219 Description GDUT中有个风云人 ...
随机推荐
- Linux上Simplescalar/ARM的安装和运行文档
本文是基于ARM的simplescalar在ubuntu下的安装说明 1.1 软件下载 *********************文件下载地址:http://yunpan.cn/cw2n7dAyfG ...
- 06-HTML-表格标签
<html> <head> <title>表格标签学习</title> <meta charset="utf-8"/> ...
- js 移动端上拉刷新(基于ng1)
//分页下拉 var ajaxScroll = function() { var screenHeight = window.screen.height; $(document).scroll(fun ...
- SAP FI配置步骤
http://blog.sina.com.cn/s/blog_8eda1a620100uwzj.html No. 配置对象 事务代码 配置内容 路径 备注 1 定义公司 OX15 企业结构>定义 ...
- p标签内容实现第二行缩进两个字体间距
p{ word-break:normal; text-indent: -2em; margin-left: 2em;} <p> p标签实现自动换行:p标签实现自动换行:p标签实现自动换行: ...
- python与html5 websocket开发聊天对话窗
1.下载必须的包 https://github.com/Pithikos/python-websocket-server,解压缩并把文件夹名‘python-websocket-server-maste ...
- shell中的set、seq、eval、exec、&&和||
一.set 查看set 帮助: bash -c "help set" 选项: -e:任何命令执行失败(非0 status)直接退出 -x: 打印执行过程的命令行.参数 +e:命令执 ...
- 使用html+css+js实现简易计算器
使用html+css+js实现简易计算器, 效果图如下: html代码如下: <!DOCTYPE html> <html lang="en"> <he ...
- mssql instead of 触发器应用一-创建只读视图(view)的方法
转自: http://www.maomao365.com/?p=4906 <span style="color:white;background-color:blue;font-wei ...
- Essential pro angular and asp.net core 笔记
1. dotnet ef相关命令 删除数据库(适合只有一个数据库的情形) dotnet ef database drop --force 更新数据库(适合只有一个数据库的情形) dotnet ef d ...