思路:简单模拟即可。判断一下是不是回文,是回文看长度是不是偶数。是偶数的话,说明又可能是回文。依次这样处理。但是只要长度为奇数则一定是原来的长度直接输出即可。

#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 国王的魔镜的更多相关文章

  1. 洛谷——P2799 国王的魔镜

    P2799 国王的魔镜 题目描述 国王有一个魔镜,可以把任何接触镜面的东西变成原来的两倍——只是,因为是镜子嘛,增加的那部分是反的.比如一条项链,我们用AB来表示,不同的字母表示不同颜色的珍珠.如果把 ...

  2. 洛谷 P2799 国王的魔镜

    把项链当做字符串输进去,可以用gets #include<iostream>#include<cstdio>#include<cmath>#include<c ...

  3. P2799国王的魔镜

    链接 想了好久(蒟蒻的不能蒟蒻) 题解: #include<iostream>#include<cstdio>#include<cstring>#include&l ...

  4. 【BZOJ】3850: ZCC Loves Codefires(300T就这样献给了水题TAT)

    http://www.lydsy.com/JudgeOnline/problem.php?id=3850 题意:类似国王游戏....无意义.. #include <cstdio> #inc ...

  5. HDOJ 2317. Nasty Hacks 模拟水题

    Nasty Hacks Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tota ...

  6. ACM :漫漫上学路 -DP -水题

    CSU 1772 漫漫上学路 Time Limit: 1000MS   Memory Limit: 131072KB   64bit IO Format: %lld & %llu Submit ...

  7. ytu 1050:写一个函数,使给定的一个二维数组(3×3)转置,即行列互换(水题)

    1050: 写一个函数,使给定的一个二维数组(3×3)转置,即行列互换 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 154  Solved: 112[ ...

  8. [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 ...

  9. gdutcode 1195: 相信我这是水题 GDUT中有个风云人物pigofzhou,是冰点奇迹队的主代码手,

    1195: 相信我这是水题 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 821  Solved: 219 Description GDUT中有个风云人 ...

随机推荐

  1. 给大家带来一些 horm的一些知识!

    1. form action 提交地址     https://www.baidu.com merhod 提交 方式post get get是在http的url上提交不加密 post加密在http 中 ...

  2. mysql date_format()函数

    DATE_FORMAT(DATE,FORMAT)函数 占位符 说明 %a 缩写的星期几(Sun.....Sat) %b 缩写的月份(Jan.....Dec)  %c 数字形式的月份(1.......1 ...

  3. LintCode Majority Number II / III

    Given an array of integers, the majority number is the number that occurs more than 1/3 of the size ...

  4. ThinkPHP登录功能的实现方法

    登陆功能是PHP程序设计中常见的功能.本文ThinkPHP实例主要完成注册成功后进入首页,并告诉你是登录用户的功能.具体实现步骤如下: 第一步:在config.php文件中加上: 完整实现代码如下: ...

  5. Neutron中插件与代理的总结

    1.总结:

  6. java内存分配与垃圾回收

    JVM的内存分配主要基于两种,堆和栈. 我们来看一下java程序运行时候的内存分配策略: 1):静态存储区(方法区): 2):栈区: 3):堆区: 1):主要存放静态数据,全局static数据和常量. ...

  7. react-router-dom v^4路由、带参路由的配置

    首先安装路由 npm install --save react-router-dom 新建一个router.js文件 然后我们的router.js代码如下↓ import React from 're ...

  8. Android Dialog对话框

    Dialog的基本方法 //创建Dialog AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); //设 ...

  9. (网页)websocket后台调用Service层

    百度论坛里面有很多好的方法,借鉴. 重点:因为项目是StringBoot所以我用的是下面的方法很好使: Service.... service = (Service....) ContextLoade ...

  10. 添加用户到sudoers

    ** is not in the sudoersfile.  This incident will bereported.” (用户不在sudoers文件中……) 处理这个问题很简单,但应该先理解其原 ...