遍历一遍字符串,一位一位的比较即可
#include<iostream> using namespace std; int main() { string S; cin>>S; string s1="XiaoQiao"; string s2="XiaoHuiHui"; int len1 = s1.length(); int len2 = s2.length(); int index1 = 0,index2=0; for(int i = 0 ; i < S.length();i++) { if(S[i]==s1[index1]&&index1<len1) { index1++; } if(S[i]==s2[index2]&&index2<len2) { index2++; } } if(index1==len1 && index2==len2) { cout<<"Happy"<<endl; } else{ cout<<"emm"<<endl; } return 0; }