houhaoxuan


私信TA

用户名:dotcpp0607776

访问量:421

签 名:

等  级
排  名 24895
经  验 551
参赛次数 0
文章发表 5
年  龄 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分

1 人评分

  评论区