0
点赞
收藏
分享

微信扫一扫

国腾GM8775C完全替代CS5518 MIPIDSI转2 PORT LVDS

双井暮色 2023-10-25 阅读 135

Problem - 1321C - Codeforces

解析:

        贪心,从z到a遍历,每次循环减去符合题意的字符。

#include<bits/stdc++.h>
using namespace std;
signed main(){
	int n;
	string s;
	cin>>n>>s;
	for(char i='z';i>'a';i--){
		for(int j=0;j<s.size();j++){
			if(s[j]==i){
				if(j!=0&&s[j-1]==i-1) s.erase(j,1),j=-1;
				else if(j!=s.size()-1&&s[j+1]==i-1) s.erase(j,1),j=-1;	
			}
		}
	}
	cout<<n-s.size();
	return 0;
}
举报

相关推荐

0 条评论