-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1321C.cpp
36 lines (34 loc) · 880 Bytes
/
1321C.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include "bits/stdc++.h"
using i64 = long long int;
using namespace std;
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define inarr(a,n) for(int i = 0; i < n; ++i) cin >> a[i];
#ifndef ONLINE_JUDGE
#define db(x) cerr << #x <<" = " << x << "\n";
#else
#define db(...)
#endif
//
void solve(){
int n;cin >> n;
string s,t;cin >> s;t=s;
while(true){
int mx = -1, mi = -1;
for(int i=0;i<sz(s);++i){
if(i>0 && s[i]-s[i-1]==1 && (s[i]-'a') > mx){mx = s[i]-'a'; mi = i;}
else if(i<sz(s) && s[i]-s[i+1]==1 && (s[i]-'a') > mx){mx = s[i]-'a'; mi = i;}
}
if(mx == -1)break;
s.erase(s.begin() + mi);
}
cout << n - sz(s);
}
int main(){
cin.tie(nullptr);cout.tie(nullptr);ios::sync_with_stdio(false);
int t = 1;
// cin >> t;
while(t--){
solve();
}
}