This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |