Josif_tepe

Untitled

Aug 30th, 2026
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.26 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <cstring>
  5. #include <map>
  6. using namespace std;
  7. typedef long long ll;
  8.  
  9. string S;
  10.  
  11. ll count_palindromes(const string & s) {
  12.     ll res = 0;
  13.     for(int i = 0; i < (int) s.size(); i++) {
  14.         string tmp = "";
  15.         for(int j = i; j < (int) s.size(); j++) {
  16.             tmp += s[j];
  17.             int S = 0, E = (int) tmp.size() - 1;
  18.             bool ok = true;
  19.             while(S < E) {
  20.                 if(tmp[S] != tmp[E]) {
  21.                     ok = false;
  22.                     break;
  23.                 }
  24.                 S++;
  25.                 E--;
  26.             }
  27.             if(ok) {
  28.                 res++;
  29.             }
  30.         }
  31.     }
  32.     return res;
  33. }
  34. int main() {
  35.     ios_base::sync_with_stdio(false);
  36.     cin >> S;
  37.     vector<char> c;
  38.     vector<bool> visited(26, false);
  39.     for(char x: S) {
  40.         if(!visited[x - 'a']) {
  41.             c.push_back(x);
  42.             visited[x - 'a'] = true;
  43.         }
  44.     }
  45.     ll res = 0;
  46.     for(int i = 0; i < (int) S.size(); i++) {
  47.         string tmp = S;
  48.         for(char x: c) {
  49.             tmp[i] = x;
  50.             res = max(res, count_palindromes(tmp));
  51.         }
  52.     }
  53.     cout << res << endl;
  54.    
  55.    
  56.     return 0;
  57. }
  58.  
Advertisement
Add Comment
Please, Sign In to add comment