#include <iostream>
const int SIGMA = 26;
struct Trie {
int words;
Trie* children[SIGMA];
Trie() {
words = 0;
for (int i = 0; i < SIGMA; i++) {
children[i] = NULL;
}
}
};
void insert(Trie* root, char* S) {
if (*S == '\0') {
root->words++;
} else {
if (root->children[S[0] - 'a'] == NULL) {
root->children[S[0] - 'a'] = new Trie();
}
insert(root->children[S[0] - 'a'], S + 1);
}
}
void dfs(Trie* root) {
for (int i = 1; i <= root->words; i++) {
std::cout << "P\n";
}
for (int i = 0; i < SIGMA; i++) {
if (root->children[i] != NULL) {
std::cout << char(i + 'a') << "\n";
dfs(root->children[i]);
std::cout << "-\n";
}
}
}
int main() {
Trie root;
char* S = new char[20 + 1];
int n;
std::cin >> n;
for (int i = 1; i <= n; i++) {
std::cin >> S;
insert(&root, S);
}
dfs(&root);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Expected integer, but "t" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Expected integer, but "e" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Expected integer, but "h" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Expected integer, but "b" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Expected integer, but "a" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
1740 KB |
Expected integer, but "a" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
8 ms |
5800 KB |
Expected integer, but "a" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
21 ms |
14352 KB |
Expected integer, but "a" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
75 ms |
35896 KB |
Expected integer, but "a" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
46 ms |
27988 KB |
Expected integer, but "a" found |
2 |
Halted |
0 ms |
0 KB |
- |