题目: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;
}