Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define IOS \
- ios::sync_with_stdio(0); \
- cin.tie(0); \
- cout.tie(0);
- #define endl "\n"
- #define int long long
- #define watch(x) cout << (#x) << " is " << (x) << endl;
- int32_t main()
- {
- IOS;
- int n, ans = 0;
- cin >> n;
- string s;
- cin >> s;
- for (char c = 'z'; c >= 'a'; c--)
- {
- for (int i = 0; i < s.size(); i++)
- {
- if (s[i] == c)
- if ((i > 0 && s[i] - 1 == s[i - 1]) || (i < s.size() - 1 && s[i] - 1 == s[i + 1]))
- {
- s.erase(i, 1);
- ans++;
- i = i - 1;
- }
- }
- }
- cout << ans << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment