Codeforces 1321C Remove Adjacent
作者:互联网
2s+n=100,可以直接暴力贪心,从末尾z开始删到a即可
#include<bits/stdc++.h>
using namespace std;
#define ms(x,y) memset(x, y, sizeof(x))
#define lowbit(x) ((x)&(-x))
typedef long long LL;
typedef pair<int,int> pii;
void run_case() {
int n;
string str;
cin >> n >> str;
int ans = 0;
for(int k = 25; k >= 0; --k) {
for(int t = 0; t < 100; ++t) {
for(int i = 0; i < str.size(); ++i) {
if((str[i] - 'a' == k) && ((str[i-1] - 'a' == k-1) || (str[i+1] - 'a' == k-1))) {
ans++;
str.erase(i, 1);
i--;
}
}
}
}
cout << ans;
}
int main() {
ios::sync_with_stdio(false), cin.tie(0);
cout.flags(ios::fixed);cout.precision(2);
//int t; cin >> t;
//while(t--)
run_case();
cout.flush();
return 0;
}
标签:typedef,Adjacent,int,Codeforces,long,++,1321C,str,ans 来源: https://www.cnblogs.com/GRedComeT/p/12442873.html