简单题。

#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. cookie工作原理

    当客户访问某个基于PHP技术的网站时,在PHP中可以使用setcookie()函数生成一个cookie,系统经处理把这个cookie发送到客户端并保存在C:\Documents andSettings ...

  2. 1095. Cars on Campus (30)

    Zhejiang University has 6 campuses and a lot of gates. From each gate we can collect the in/out time ...

  3. backbone collection add 事件回调参数

    this.listenTo(this.collection, 'add', this.renderBook); renderBook: function (item) { var bookView = ...

  4. UML中的六大关系

    转自:http://www.cnblogs.com/shengtianlong/archive/2010/10/23/1858953.html UML定义的关系主要有六种:依赖.类属.关联.实现.聚合 ...

  5. 什么是ajax,ajax原理是什么 ,优缺点是什么

    AJAX工作原理及其优缺点   1.什么是AJAX?AJAX全称为“Asynchronous JavaScript and XML”(异步JavaScript和XML),是一种创建交互式网页应用的网页 ...

  6. 微软职位内部推荐-Android Developer

    微软近期Open的职位: Position: SDE II or Senior SDE -- Mobile Products Android/WP Contact Person: Winnie Wei ...

  7. SQL Server 数据库最小宕机迁移方案

    一.目的 在做SQL Server数据库维护的时候,当上司要求我们把几十G的数据文件搬动到其它服务器,并且要求最小宕机时间的时候,我们有没什么方案可以做到这些要求呢? 在这里我们假设这两台机器并不是在 ...

  8. c语言函数指针的理解与使用

    1.函数指针的定义 顾名思义,函数指针就是函数的指针.它是一个指针,指向一个函数.看例子: A) char * (*fun1)(char * p1,char * p2); B) char * *fun ...

  9. How to use Android Activity's finish(), onDestory() and System.exit(0) methods

    Activity.finish() Calling this method will let the system know that the programmer wants the current ...

  10. 框架优化系列文档:SVN中非版本控制文件忽略上传的设置

    对于SVN代码库,只应该上传源代码.资源文件等内容进行版本管理,通常编译后的二进制文件.程序包等生成产物是不应该放到SVN上做版本管理的.因此在svn的客户端工具中设置svn的属性:svn:ignor ...