简单题。

#include <iostream>
#include <string>
using namespace std; int main() {
int T;
cin >> T;
while (T--) {
string s;
cin >> s;
int l = 0;
int r = s.size() - 1;
while (l < r && s[l] == s[r]) {
l++;
r--;
}
if (l >= r) {
cout << -1 << endl;
continue;
}
int ll = l + 1;
int rr = r;
while (ll < rr && s[ll] == s[rr]) {
ll++;
rr--;
}
if (ll >= rr) {
cout << l << endl;
} else {
cout << r << endl;
}
}
return 0;
}

  

[hackerrank]Palindrome Index的更多相关文章

  1. Palindrome Index

    传送门: Palindrome Index Problem Statement You are given a string of lower case letters. Your task is t ...

  2. LintCode Palindrome Partitioning II

    Given a string s, cut s into some substrings such that every substring is a palindrome. Return the m ...

  3. LeetCode 214 Shortest Palindrome

    214-Shortest Palindrome Given a string S, you are allowed to convert it to a palindrome by adding ch ...

  4. 【Leetcode】【Medium】Palindrome Partitioning

    Given a string s, partition s such that every substring of the partition is a palindrome. Return all ...

  5. Leetcode | Palindrome

    Valid Palindrome Given a string, determine if it is a palindrome, considering only alphanumeric char ...

  6. POJ2402/UVA 12050 Palindrome Numbers 数学思维

    A palindrome is a word, number, or phrase that reads the same forwards as backwards. For example,the ...

  7. [LeetCode#266] Palindrome Permutation

    Problem: Given a string, determine if a permutation of the string could form a palindrome. For examp ...

  8. Palindrome Pairs 解答

    Question Given a list of unique words, find all pairs of distinct indices (i, j) in the given list, ...

  9. Reverse Integer - Palindrome Number - 简单模拟

    第一个题目是将整数进行反转,这个题实现反转并不难,主要关键点在于如何进行溢出判断.溢出判断再上一篇字符串转整数中已有介绍,本题采用其中的第三种方法,将数字转为字符串,使用字符串比较大小的方法进行比较. ...

随机推荐

  1. Ubuntu14.04忘记root密码的解决方法

    电脑20多天没用忘记密码了,下面是在网上找到的一个解决办法,其它的和这个也大概相同.因为其中有些缺漏,没能给我解决问题.通过分析最终问题还是解决了,现解决方案的关键点记录一下.希望能方便到其它人. 1 ...

  2. WPF-控件-层级控件-TreeView

    <?xml version="1.0" encoding="utf-8" ?> <Data xmlns=""> &l ...

  3. php protected只能被继承,不可以在实例中调用,parent::调用父类(子类函数的重载对父类的函数没有影响)

    <?php class a { private function fun1(){ echo 'a1'; } //protected 可以被继承,但是只能在子类中使用,不能被实例化调用 prote ...

  4. ubuntu12.04之后该死的文件关联

    这是抱怨贴~~~当然也提供了解决方法~敬请期待. 这个帖子中我们介绍如何在ubuntu下安装quartus II 13.1,安装完毕功能正常,但是有个“小问题”就是如何在文件管理器中(这里是nauti ...

  5. Configure xterm Fonts and Colors for Your Eyeball

    https://wiki.mpich.org/mpich/index.php/Configure_xterm_Fonts_and_Colors_for_Your_Eyeball Screenshot ...

  6. VBS基础篇 - 数组

    数组变量:有时需要向一个单一的变量赋于多个值,那么您可以创建一个可包含一系列值的变量,这种变量被称为数组. '静态数组 ) a()="George" a()="john& ...

  7. crawler spec

    使用说明 0.写在前面 1.本程序完成的抓取网页并保存其文件的工作. 2.目前的版本还需将工程文件导入eclipse中运行. 3.加载主类MyCrawler生成可执行文件. 4.程序主界面: 1 准备 ...

  8. Hadoop启动异常情况解决方案

    1. 启动时报WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using b ...

  9. jquery插件——图片放大器

    用到了JQzoom插件,可以使图片实现放大效果

  10. IIS 分析器错误消息: 未能加载类型“_Default”

    还会出现不能加载程序集,如: using Model;using BLL;  均报错 但是在vs2012  iis express中调试正常, 按照网上方法: 我将vs  web项目下的目录全部cop ...