arten_1337

Untitled

Mar 2nd, 2020
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.77 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define IOS                  \
  5.     ios::sync_with_stdio(0); \
  6.     cin.tie(0);              \
  7.     cout.tie(0);
  8. #define endl "\n"
  9. #define int long long
  10. #define watch(x) cout << (#x) << " is " << (x) << endl;
  11.  
  12. int32_t main()
  13. {
  14.     IOS;
  15.  
  16.     int n, ans = 0;
  17.     cin >> n;
  18.     string s;
  19.     cin >> s;
  20.  
  21.     for (char c = 'z'; c >= 'a'; c--)
  22.     {
  23.         for (int i = 0; i < s.size(); i++)
  24.  
  25.         {
  26.             if (s[i] == c)
  27.                 if ((i > 0 && s[i] - 1 == s[i - 1]) || (i < s.size() - 1 && s[i] - 1 == s[i + 1]))
  28.                 {
  29.                     s.erase(i, 1);
  30.                     ans++;
  31.                     i = i - 1;
  32.                 }
  33.         }
  34.     }
  35.     cout << ans << endl;
  36.  
  37.     return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment