找到字符串中easy的字符个数, (1)easy中字符相对顺序不变 (2)下一个easy的e必须在前一个easy的y之后 不明白为啥只过了27
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int func(string &s, int a,int b){
int k=0;
int m=0,n=0,x=0;
for(int i=a+1;i<=b;i++){
if(s[i]=='A' || s[i]=='a'){
m=i;break;
}
}
for(int i=a+1;i<=b;i++){
if(s[i]=='S' || s[i]=='s'){
n=i;break;
}
}
for(int i=a+1;i<=b;i++){
if(s[i]=='Y' || s[i]=='y'){
x=i;break;
}
}
if(m=0 || n==0 || x==0){
k=0;
}
if(m<n<x){
k=1;
}
return k;
}
int main(){
string s;cin>>s;
int num=0;
vector<int> arr;
for(int i=0;i<s.size();i++){
if(s[i]=='e' || s[i]=='E'){
arr.push_back(i);
}
}
int i=0;
cout<<arr.size()<<endl;
if(arr.empty() ){
cout<<num<<endl;
}
if(arr.size()==1){
num += func(s,arr[0],arr.size());
cout<<num<<endl;
}
else{
for(;i<arr.size()-1;i++){
num += func(s,arr[i],arr[i+1]-1);
}
num += func(s,arr[i],s.size());
cout<<num<<endl;
}
return 0;
}
|