#include<bits/stdc++.h>
using namespace std;
vector<char> v;
struct trie
{
int nr, rasp;
trie *fii[27];
};
trie* init = new trie();
void add(trie *t, char *c)
{
t -> nr++;
if(*c == '\0')
{
t -> rasp++;
return;
}
if(t -> fii[*c - 'a'] == NULL)
t -> fii[*c - 'a'] = new trie();
add(t -> fii[*c - 'a'], c + 1);
}
void ans(trie *t)
{
for(int i = 1; i <= t -> rasp; i++)
v.push_back('P');
for(int i = 0; i < 26; i++)
{
if(t -> fii[i] != NULL)
{
v.push_back(char(i + 'a'));
ans(t -> fii[i]);
}
}
v.push_back('-');
}
int main()
{
//freopen("trie.in", "r", stdin);
//freopen("trie.out", "w", stdout);
int n;
char y[27];
cin >> n;
for(int i = 1; i <= n; i++)
{
cin >> y;
add(init, y);
}
ans(init);
while(v.back() == '-')
v.pop_back();
for(auto u : v)
cout << u << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Expected integer, but "t" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Expected integer, but "e" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Expected integer, but "h" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Expected integer, but "b" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
504 KB |
Expected integer, but "a" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
1872 KB |
Expected integer, but "a" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
10 ms |
6272 KB |
Expected integer, but "a" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
26 ms |
15676 KB |
Expected integer, but "a" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
64 ms |
38852 KB |
Expected integer, but "a" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
51 ms |
30408 KB |
Expected integer, but "a" found |
2 |
Halted |
0 ms |
0 KB |
- |