5 条题解

  • 0
    @ 2024-11-22 21:35:17
    #include<bits/stdc++.h>
    template<class T>inline void read(T &x){x=0;char c=getchar();bool f=0;for(;!isdigit(c);c=getchar())if(c=='-')f=1;for(;isdigit(c);c=getchar())x=(x<<3)+(x<<1)+c-'0';x=f?(~(x-1)):x;}
    template<class T>inline void write(T x){if(x<0)return putchar('-'),write(-x),void();if(x>=10)write(x/10);putchar(x%10+'0');return;}
    template<class T>inline void print(T x){write(x);putchar('\n');}
    template<typename type,typename ...T>inline void read(type &x,T&...y){read(x),read(y...);}
    using namespace std;
    const int N=505;
    int n,q;
    string s,t[N];
    inline int check(int pos){
    	int ans=0;
    	for(int i=1;i<=q;++i){
    		int len=t[i].length()-1;
    		bool same=1;
    		if(pos+len-1>n)same=0;
    		else{
    			for(int j=1;pos+j-1<=n&&j<=len;++j){
    				if(t[i][j]!=s[pos+j-1]){
    					same=0;
    					break;
    				}
    			}
    		}
    		if(same==1){
    			ans++;
    		}
    	}
    	return ans;
    }
    int result;
    signed main(){
    	read(n);
    	cin>>s;
    	s=" "+s;
    	read(q);
    	for(int i=1;i<=q;++i){
    		cin>>t[i];
    		t[i]=" "+t[i];
    	}
    	for(int i=1;i<=n;++i){
    		result+=check(i);
    	}
    	print(result);
    	return 0;
    }
    

    信息

    ID
    958
    时间
    1000ms
    内存
    256MiB
    难度
    6
    标签
    (无)
    递交数
    161
    已通过
    50
    上传者