蒟蒻求调代码T-T
  • 板块灌水区
  • 楼主Secret_Sky_2021
  • 当前回复0
  • 已保存回复0
  • 发布时间2023/8/13 20:36
  • 上次更新2023/11/3 04:01:34
查看原帖
蒟蒻求调代码T-T
601270
Secret_Sky_2021楼主2023/8/13 20:36
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=1e5+10,M=1e2+10;
string c;
int cou=0,endd[N],tre[N][M],tot=0;
void inset(string b){
	int p=1;
	for(int i=0;i<b.size();i++){
		if(!tre[p][b[i]-'a']) tre[p][b[i]-'a']=++tot;
		p=tre[p][b[i]-'a'];
	}
	endd[p]=1;
}
int main(){
	memset(tre,0,sizeof(tre));
	while(1){
		while(1){
			cin>>c;
			if(c=="#") break;
			else inset(c);
		}
		int ans=0;
		for(int i=1;i<=tot;i++){
			ans+=endd[i];
		}
		cout<<ans<<endl;
	}
	
	return 0;
}
/*
you are my friend
#
-------------------
4
*/

普普通通的字典树模板

2023/8/13 20:36
加载中...