Ancient Printer

为找规律题  结果为   节点数*2-最长字段+字段个数

结点不能设置为0   与判断条件相冲突

#include<bits/stdc++.h>
using namespace std;

int  trie[400100][26]={0};
int  sum[400100];
char ans[50005][30];//这里数组开小了导致一直wa
int root=0;
int pos;
void insert1(char *s)
{
    int root=0;
    for(int i=0;i<strlen(s);i++)
    {   int ch=s[i]-'a';
        if( trie[ root ][ch]==0  )
          {
             memset(trie[pos],0,sizeof(trie[pos]));//用多少初始化多少
             trie[root][ch]=pos++;

          }
        root=trie[root][ch];
    }

}



int main()
{



    int n;
    while(scanf("%d",&n)==1)
    {
        pos=1;
        memset(trie[0],0,sizeof(trie[0]));//用多少初始化多少
        int maxx=0;
        for(int i=1;i<=n;i++)
        {  char a[50];
            scanf("%s",a);
            maxx=maxx>strlen(a)?maxx:strlen(a);
            insert1(a);



        }
        printf("%d
",(pos-1)*2-maxx+n);



    }






return 0;
}
原文地址:https://www.cnblogs.com/bxd123/p/10346160.html