Trie
记录结点数
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#define MOD ((int)(1e9) + 7)
#define eps 1e-10
using namespace std;
typedef long long ll;
#define sigma_size 110
#define maxnode 100010
int res;
struct Trie {
struct Node {
int ch[sigma_size], value, cnt;
void init() {
memset(ch, 0, sizeof(ch));
value = 0;
cnt = 0;
}
};
Node node[maxnode];
int used, root;
int P(char ch) {
if ('0' <= ch && ch <= '9') return ch - '0';
if ('a' <= ch && ch <= 'z') return 10 + ch - 'a';
if ('A' <= ch && ch <= 'Z') return 36 + ch - 'A';
return 62;
}
int newNode() {
node[used].init();
return used ++;
}
void init() {
used = 0;
root = newNode();
}
void Add(string &s, int v) {
int x = root;
for (int i = 0; i < s.size(); ++ i) {
int p = P(s[i]);
if (!node[x].ch[p]) node[x].ch[p] = newNode();
node[x].cnt ++;
x = node[x].ch[p];
}
node[x].value = v;
}
void Query(string &s) {
int x = root;
for (int i = 0; i < s.size(); ++ i) {
int p = P(s[i]);
node[x].cnt --;
if (node[x].cnt == 0) return;
res ++;
x = node[x].ch[p];
}
}
}tx;
string str[100010];
int main() {
int n;
while (scanf("%d", &n) != EOF) {
tx.init();
res = 0;
for (int i = 0; i < n; ++ i) {
cin >> str[i];
tx.Add(str[i], -1);
}
for (int i = 0; i < n-1; ++ i) {
tx.Query(str[i]);
}
printf("%.6lf\n",(double)res);
}
}