代码wa了。先放着等以后找问题
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
struct Node {
int num;
Node *Lu[10];
Node() {
num = 0;
for (int i = 0; i < 10; i++)
Lu[i] = NULL;
}
};
int n;
Node *root = new Node;
Node *current, *newnode;
int insert(char *str) {
int m;
current = root;
for (int i = 0; i < strlen(str); i++) {
m = str[i] - '0';
if (current->Lu[m] != NULL) {
current = current->Lu[m];
if (i == strlen(str) - 1) {
++(current->num);
n = current->num;
return n;
}
}
else {
newnode = new Node;
current->Lu[m] = newnode;
if (i == strlen(str) - 1) {
++(current->Lu[m]->num);
n = current->Lu[m]->num;
return n;
}
current = newnode;
}
}
}
int main() {
int Max, T;
string Yi;
char Zheng[31];
while (cin >> T) {
if (T == 0) {
cout << 1 << endl;
continue;
}
Max = 0;
n = 0;
for (int i = 0; i < T; i++) {
memset(Zheng, 0, sizeof(Zheng));
cin >> Yi;
int j, q = 0;
for (j = 0; j < Yi.length(); j++) {
if (Yi[j] != '0')
break;
}
for (int k = j; k < Yi.length(); k++)
Zheng[q++] = Yi[k];
Max = max(Max, insert(Zheng));
}
cout << Max << endl;
delete root;
root = new Node;
}
return 0;
}