Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #include <cstring>
- #include <map>
- using namespace std;
- typedef long long ll;
- string S;
- ll count_palindromes(const string & s) {
- ll res = 0;
- for(int i = 0; i < (int) s.size(); i++) {
- string tmp = "";
- for(int j = i; j < (int) s.size(); j++) {
- tmp += s[j];
- int S = 0, E = (int) tmp.size() - 1;
- bool ok = true;
- while(S < E) {
- if(tmp[S] != tmp[E]) {
- ok = false;
- break;
- }
- S++;
- E--;
- }
- if(ok) {
- res++;
- }
- }
- }
- return res;
- }
- int main() {
- ios_base::sync_with_stdio(false);
- cin >> S;
- vector<char> c;
- vector<bool> visited(26, false);
- for(char x: S) {
- if(!visited[x - 'a']) {
- c.push_back(x);
- visited[x - 'a'] = true;
- }
- }
- ll res = 0;
- for(int i = 0; i < (int) S.size(); i++) {
- string tmp = S;
- for(char x: c) {
- tmp[i] = x;
- res = max(res, count_palindromes(tmp));
- }
- }
- cout << res << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment