# 1107 : Shortest Proper Prefix

Query auto-completion(QAC) is widely used in many search applications. The basic idea is that when you type some string s in the search box several high-frequency queries which have s as a prefix are suggested. We say string s1 has string s2 as a prefix if and only if the first |s2| characters of s1 are the same as s2 where |s2| is the length of s2.

These days Little Hi has been working on a way to improve the QAC performance. He collected N high-frequency queries. We say a string s is a proper prefix if there are no more than 5 collected queries have s as a prefix. A string s is a shortest proper prefix if s is a proper prefix and all the prefixes of s(except for s itself) are not proper prefixes. Little Hi wants to know the number of shortest proper prefixes given N collected queries.

Hint: the 4 shortest proper prefixes for Sample Input are “ab”, “bb”, “bc” and “be”. Empty string “” is not counted as a proper prefix even if N <= 5.

The first line contains N(N <= 10000), the number of collected queries.

The following N lines each contain a query.

Each query contains only lowercase letters ‘a’-‘z’.

The total length of all queries are no more than 2000000.

Input may contain identical queries. Count them separately when you calculate the number of queries that have some string as a prefix.

Output the number of shortest proper prefixes.

12
a
ab
abc
abcde
abcde
abcba
bcd
bcde
bcbbd
bcac
bee
bbb

4

//trie树

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <algorithm>
#include <map>
#include <vector>

using namespace std;

struct trie{ //建立一颗字典树
char key;
int num;
trie *next[26];
trie(){
num = 0;
for(int i = 0; i < 26; i++) next[i] = NULL;
}

};

trie root;//创建根节点

void ins(string s) { //插入新单词

for(int i = 0; i < s.size(); i++) {
int k = s[i] - 'a';

trie *node = new trie;
node->key = s[i];

}
}

}

int ans = 0; //题目所述proper prefix的个数
map<trie *,int>k; //建立一个映射，后面会用到

for(int i = 0; i < 26; i++) {
int flag = 0;

ans++;
flag = 1; //标记，此节点后面的分支都不用再遍历了
}

//不是最后一个节点且前面还没遇到满足条件的节点

}

}

int main(){

string s;
int n,m;
cin >> n;
while(n--) {
cin >> s;
ins(s);
}

}