0
点赞
收藏
分享

微信扫一扫

AcWing 3358. 放养但没有完全放养(贪心)

自由的美人鱼 2022-04-19 阅读 43

题目:3358. 放养但没有完全放养

在这里插入图片描述
在这里插入图片描述
题解:先记录下每个字母在第几位,然后对字符串中相邻字母在字母表的位置进行判断,如果是升序的不用ct++,否则要

#include<bits/stdc++.h>
#define x first
#define y second
using namespace std;
typedef long long LL;
typedef pair<int ,string> PII;
const int N=1e4;
const int mod=100000007;
int a[30];
int main(){
    char t;
    for(int i=1;i<=26;i++){
        cin>>t;
        a[t-'a']=i;
    }
    string s;
    cin>>s;
    int ct=1;
    for(int i=1;i<s.size();i++){
        if(a[s[i]-'a']<=a[s[i-1]-'a']){
            ct++;
        }
    }
    cout<<ct;
    return 0;
}


举报

相关推荐

0 条评论