本地运行无输出,但交上去过了
查看原帖
本地运行无输出,但交上去过了
1432013
DashZhanghanxu楼主2025/6/15 21:10

求解答

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define O2 ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
int tree[500001][130];
int cnt[500001];
string s;
int idx;
int n;
int all=0;
void insert(string s){
	int p=0;
	for(int i=0;i<s.size();i++){
		int t=s[i];
		if(!tree[p][t]){
			tree[p][t]=++idx;
		}
		p=tree[p][t]; 
	}   
	cnt[p]=1;
}
int mark=0;
int query(string s){
	int p=0;
	for(int i=0;i<s.size();i++){
		int t=s[i];
		if(!tree[p][t]){
			return 0;
		}
		p=tree[p][t];
	}
	//if(cnt[p]==0)return 0;
	return cnt[p];
}
int maxans=0;
signed main(){
    O2;
    s="";
    insert(s);
    while(s!="666"){
    	s="666";
    	cin>>s;
    	if(s=="666")break;
    	insert(s);
	}
	cout<<idx+1;
    return 0;
}

2025/6/15 21:10
加载中...