解题思路:
注意事项:
参考代码:
#include<bits/stdc++.h>
using namespace std;
char s[20000];
bool fx(char* s1, char* s2) //暴力搜索s1在s2中是否存在
{
int n=0,i = 0, j = 0;
while (n != strlen(s1) && strlen(s2) - j >=strlen(s1)-n)
{
if (s1[i] == s[j])
{
i++;
j++;
n++;
}
else
{
i = 0;
j = j - n + 1;
n = 0;
}
}
return n == strlen(s1);
}
int main()
{
char c[9];
cin >> s;
int n,sum=0;
cin >> n;
while (n--)
{
cin >> c;
sort(c, c + 8); //从最小开始排序
do
{
sum+=(int)fx(c, s);
} while (next_permutation(c, c + 8)); //next_permutation实现字典排序
}
cout << sum;
}
0.0分
1 人评分