[hackerrank]Palindrome Index
简单题。
#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的更多相关文章
- Palindrome Index
传送门: Palindrome Index Problem Statement You are given a string of lower case letters. Your task is t ...
- LintCode Palindrome Partitioning II
Given a string s, cut s into some substrings such that every substring is a palindrome. Return the m ...
- LeetCode 214 Shortest Palindrome
214-Shortest Palindrome Given a string S, you are allowed to convert it to a palindrome by adding ch ...
- 【Leetcode】【Medium】Palindrome Partitioning
Given a string s, partition s such that every substring of the partition is a palindrome. Return all ...
- Leetcode | Palindrome
Valid Palindrome Given a string, determine if it is a palindrome, considering only alphanumeric char ...
- POJ2402/UVA 12050 Palindrome Numbers 数学思维
A palindrome is a word, number, or phrase that reads the same forwards as backwards. For example,the ...
- [LeetCode#266] Palindrome Permutation
Problem: Given a string, determine if a permutation of the string could form a palindrome. For examp ...
- Palindrome Pairs 解答
Question Given a list of unique words, find all pairs of distinct indices (i, j) in the given list, ...
- Reverse Integer - Palindrome Number - 简单模拟
第一个题目是将整数进行反转,这个题实现反转并不难,主要关键点在于如何进行溢出判断.溢出判断再上一篇字符串转整数中已有介绍,本题采用其中的第三种方法,将数字转为字符串,使用字符串比较大小的方法进行比较. ...
随机推荐
- 两个Activity之间的交互startActivityForResult的使用
代码如下: package com.zzw.teststartintentforrequest; import android.app.Activity; import android.content ...
- MySQL实战积累
IFNULL(expr1,expr2)的用法:假如expr1不为NULL,则IFNULL()的返回值为 expr1; 否则其返回值为expr2. 索引:http://www.cnblogs.com ...
- ASP.NET中各种连接数据库的配置
一.数据库连接语句 1.MSSQL数据库链接示例 <connectionStrings> <add name="Conn" connectionString=&q ...
- Translation perface: <<Professional JavaScript for Web Developers, 3rd Edition>>
It is a huge pitty to breaking translating this book. Sincerly speaking, I am striken by this great ...
- Windows Server 2008 R2 64bit兼容Chrome浏览器
近日更换系统Windows Server 2008 R2 64bit系统,发现谷歌浏览器插件无法正常运行,终于找到如下解决方案: 打开桌面谷歌浏览器属性,将target目标 C:\Users\Admi ...
- Daject初探之Record模型
上一篇博文我简单介绍了Daject以及Daject的Table模型,Table模型是对一张数据表的抽象,从数据表的级别处理数据,而Record模型是对单条数据记录的抽象,从记录的级别处理数据. 这一篇 ...
- js SVG
Snap.svg Paths.js http://www.sitepoint.com/creating-animated-valentines-day-card-snap-svg/
- [转载]C# FTP操作工具类
本文转载自<C# Ftp操作工具类>,仅对原文格式进行了整理. 介绍了几种FTP操作的函数,供后期编程时查阅. 参考一: using System; using System.Collec ...
- 【Leetcode】 - Divide Two Integers 位运算实现整数除法
实现两个整数的除法,不许用乘法.除法和求模.题目被贴上了BinarySearch,但我没理解为什么会和BinarySearch有关系.我想的方法也和BS一点关系都没有. 很早以前我就猜想,整数的乘法是 ...
- html+css学习笔记 [基础1]
---------------------------------------------------------------------------------------------------- ...