简单题。

#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. Silverlight动画学习笔记(三):缓动函数

    (一)定义: 缓动函数:可以将自定义算术公式应用于动画 (二)为什么要用缓动函数: 您可能希望某一对象逼真地弹回或其行为像弹簧一样.您可以使用关键帧动画甚至 From/To/By 动画来大致模拟这些效 ...

  2. Coolpy使用教程

    ---恢复内容开始--- Coolpy使用教程 1.硬件:arduino+ Ethernet Shield w5100 2.下载硬件rom,然后将rom烧进arduino. (下载地址)http:// ...

  3. IOS_修改项目模板

    1. /Applications/Xcode.app/Contents/Developer/Library/Xcode/Templates/File\ Templates/Source/Cocoa\ ...

  4. C# 测试代码运行时间

    一.新建一个控制台程序项目Test.exe using System; using System.Collections.Generic; using System.Linq; using Syste ...

  5. php生成圆形图片

    http://files.cnblogs.com/files/adtuu/circle_image.zip

  6. ZK framework on Java

    Quick start: https://www.zkoss.org/documentation Live demo: https://www.zkoss.org/zkdemo/file_handli ...

  7. php进行多个数组合并zip

    $a = array_zip(array("Dog","Cat","Horse"), array(1,2,3), array("l ...

  8. Oracle bbed使用说明2---常用命令

    一.BBED常用命令说明 先看帮助的说明 BBED> help all SET DBA [ dba | file#, block# ] SET FILENAME 'filename' SET F ...

  9. Jquer Ajax xmlhttp请求成功了,为什么一直在error函数里面

    转载自http://www.cnblogs.com/sky_Great/archive/2013/01/18/2866861.html 并进行整理: 今天遇到了一个极其奇怪的问题,用各种工具检查都能看 ...

  10. IBM MQ Reason 2538(MQRC_HOST_NOT_AVAILABLE) 错误原因一例

    环境: .NET 4.0, MQ .NET客户端 IBM.XMS(v2.0.0.3) 测试代码如下: var factoryFactory = XMSFactoryFactory.GetInstanc ...