16分RE求助
查看原帖
16分RE求助
483209
abcddca楼主2024/4/21 10:18
#include<bits/stdc++.h>
using namespace std;
int n,t,q;
int shu[3000006][65],_end[3000006];
int tot=1;
void stuck (string s){
	int p=1;
	for(int i=0;i<s.size();i++){
		int ch;
		if(s[i]>='a'&&s[i]<='z')
		 ch=s[i]-'a';
		else if(s[i]>='A'&&s[i]<='Z')
		ch=s[i]-'A'+26;
		else
		 ch=s[i]-'0'+52;
		if(!shu[p][ch]){
			shu[p][ch]=++tot;
		}
		p=shu[p][ch];
		_end[p]++;
	}
}
int sduck(string s){
	int p=1;
	for(int i=0;i<s.size();i++){
		int ch;
		if(s[i]>='a'&&s[i]<='z')
		 ch=s[i]-'a';
		else if(s[i]>='A'&&s[i]<='Z')
		ch=s[i]-'A'+26;
		else
		 ch=s[i]-'0'+52;
		p=shu[p][ch];
		if(!p){
			return 0;
		}
	}
	return _end[p];
}

void clear_() {
	for(int i = 1; i <= tot; i++) {
		for(int j=0;j<63;j++) {
			shu[i][j]=0;
		} 
		_end[i] = 0;
	}
	tot = 1;
}

int main(){
	cin>>t;
	for(int j=1;j<=t;j++){
		cin>>n>>q;
		string s;
		for(int duck=1;duck<=n;duck++){
			cin>>s;
			stuck(s);
		}
		for(int duck=1;duck<=q;duck++){
			cin>>s;
			cout<<sduck(s)<<endl;
		}
		clear_();
	}
	return 0;
}
2024/4/21 10:18
加载中...