This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <string>
#include <vector>
using namespace std;
bool isPalindrome(vector<char> &lbuf, vector<char> &rbuf, int len) {
int i = 0;
int j = len - 1;
while (j >= 0) {
if (lbuf[i] != rbuf[j]) return false;
j--;
i++;
}
return true;
}
int main() {
int t;
cin >> t;
for (int z = 0; z < t; z++) {
string input;
cin >> input;
int l = 0, r = input.size() - 1;
vector<char> lbuf;
vector<char> rbuf;
int bufSize = 0;
int ans = 1;
while (l < r) {
lbuf.push_back(input[l]);
rbuf.push_back(input[r]);
bufSize++;
l++;
r--;
if (isPalindrome(lbuf, rbuf, bufSize)) {
ans += 2;
lbuf.clear();
rbuf.clear();
bufSize = 0;
}
}
cout << ans << endl;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |