A.小智的疑惑
暴力枚举
字串:要求必须是连续的,所以直接一位一位枚举,判断是否出现,例:
i i+1 i+2 i+3 i+4 i+5 i+6 i+7
c h u a n z h i
直接奉上代码:
#include<bits/stdc++.h>
using namespace std;
int main()
{
string s;
int sum = 0;//统计chuanzhi的数量
cin >> s;
for(int i = 0;i < s.size();i++)
{
if(s[i] == 'c' && s[i+1] == 'h' && s[i+2] == 'u' && s[i+3] == 'a' && s[i+4] == 'n' && s[i+5] == 'z' && s[i+6] == 'h' && s[i+7] == 'i')//判断这个字符串内是否有字串“chuanzhi”
sum++;//如果有,sum累加chuanzhi的次数
}
cout << sum;//输出字串“chuanzhi”出现的次数
return 0;
}