标签:blog os io div amp log size ios
简单题。
#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,布布扣,bubuko.com
标签:blog os io div amp log size ios
原文地址:http://www.cnblogs.com/lautsie/p/3911501.html