蓝桥杯 密文搜索 O(nlogn)实现

来源:互联网 发布:大淘营复制软件 编辑:程序博客网 时间:2024/06/01 15:26
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int n;
    cin>>n;
    long sum=0;
    while(n--)
    {
        string test;
        cin>>test;
        sort(test.begin(),test.end());
        long m=s.size()-test.size()+1;
        long len=m;
        while(m--)
        {
            string::iterator beg,ed;
            beg=s.begin()+len-m-1;
            ed=beg+test.size();
            string tmp(beg,ed);
            sort(tmp.begin(),tmp.end());
            if(tmp==test){
                sum++;
            }
            //cout<<tmp<<endl;//测试数据,请无视
        }
    }
    cout<<sum<<endl;
    return 0;
}
1 0
原创粉丝点击