Advertisement
7oSkaaa

Semi Palindrome

Aug 18th, 2021
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.83 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #pragma GCC optimize("0")
  3. using namespace std;
  4.  
  5. #define cin(vec) for(auto& i : vec) cin >> i
  6. #define cin_2d(vec, n, m) for(int i = 0; i < n; i++) for(int j = 0; j < m && cin >> vec[i][j]; j++);
  7. #define cout(vec) for(auto& i : vec) cout << i << " "; cout << "\n";
  8. #define cout_2d(vec, n, m) for(int i = 0; i < n; i++, cout << "\n") for(int j = 0; j < m && cout << vec[i][j] << " "; j++);
  9. #define cout_map(mp) for(auto& [f, s] : mp) cout << f << "  " << s << "\n";
  10. #define Time cerr << "Time Taken: " << (float)clock() / CLOCKS_PER_SEC << " Secs" << "\n";
  11. #define fixed(n) fixed << setprecision(n)
  12. #define ceil(n, m) (((n) / (m)) + ((n) % (m) ? 1 : 0))
  13. #define fill(vec, value) memset(vec, value, sizeof(vec));
  14. #define Num_of_Digits(n) ((int)log10(n)+1)
  15. #define all(vec) vec.begin(),vec.end()
  16. #define rall(vec) vec.rbegin(),vec.rend()
  17. #define sz(x) int(x.size())
  18. #define TC int t; cin >> t;   while(t--)
  19. #define fi first
  20. #define se second
  21. #define Pair pair < int, int >
  22. #define ll long long
  23. #define ull unsigned long long
  24. #define Mod  1'000'000'007
  25. #define INF 2'000'000'000
  26. #define EPS 1e-9
  27. #define PI acos(-1)
  28.  
  29. void Code_Crush(){
  30.   ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  31.   #ifndef ONLINE_JUDGE
  32.     freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  33.   #endif
  34. }
  35.  
  36. vector < int > freq(26);
  37.  
  38. bool check(int l, int r, string s){
  39.   freq.assign(26, 0);
  40.   for(int i = l; i <=r; i++)
  41.     freq[s[i] - 'a']++;
  42.   int odd = 0;
  43.   for(auto& i : freq)
  44.     odd += (i % 2);
  45.   return odd <= 1;
  46. }
  47.  
  48. int main(){
  49.   Code_Crush();
  50.   string s;                                                 cin >> s;
  51.   int count = sz(s);
  52.   for(int i = 0; i < sz(s); i++)
  53.     for(int j = i + 1; j < sz(s); j++)
  54.         count += check(i, j, s);
  55.   cout << count;
  56.   Time
  57.   return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement