SK


私信TA

用户名:1973231998

访问量:18343

签 名:

成功只是一时的,失败才是主旋律,笑着面对失败是主要的。

等  级
排  名 264
经  验 5663
参赛次数 0
文章发表 59
年  龄 0
在职情况 学生
学  校 *
专  业

  自我简介:

参考代码:

#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分

3 人评分

  评论区