一道求取字符串子序列的题目
#include <iostream>
#include <cstdio>
#include <string>
using namespace std;
int solution(string s, string target) {
int cnt = 0;
int index = 0;
int last = 0;
while (1) {
int j = 0;
for (int i = 0; i < s.length(); i++) {
if (s[i] == target[j]) {
j++;
if (j == target.length() ) {
j = 0;
s = s.substr(i);
cnt++;
break;
}
}
}
if (last == cnt)
return cnt;
else last = cnt;
}
}
int main() {
int T;
string target = "Jyouhou";
string s;
cin >> T;
while (T--) {
int n;
cin >> n >> s;
int x = solution(s, target);
cout << x << endl;
}
return 0;
}