文章
1
粉丝
35
获赞
3
访问
1.5k
#include "iostream"
#include "cstdio"
#include "cstring"
using namespace std;
struct Node{
int count;
Node* child[26];
Node(){
count=0;
memset(child, 0,sizeof(child));
}
};
//字符串加入前缀树中
void insertTree(string s,Node* root){
if(s.empty()){
root->count++;
return;
}
if(root->child[s[0]-'a']== nullptr){
root->child[s[0]-'a']=new Node();
insertTree(s.substr(1),root->child[s[0]-'a']);
} else{
insertTree(s.substr(1),root->child[s[0]-'a']);
}
}
int ans;
//深度优先遍历找叶节点
void DFS(Node*root){
bool flag= false;
for (int i = 0; i < 26; ++i) {
if(root->child[i]!= nullptr){
flag= true;
DFS(root->child[i]);
}
}
if(!flag){
ans++;
}
}
int main(){
int n;
string s;
while (cin>>n){
if (n==0)break;
Node*root=new Node();
w...
登录后发布评论
暂无评论,来抢沙发