#include<bits/stdc++.h>
#include<fstream>
using namespace std;
ifstream fin("inpppp.txt");
ofstream fout("outt.txt");
#define ll long long
#define vt vector
#define pb push_back
#define fi first
#define se second
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define pii pair<int, int>
#define pll pair<ll, ll>
//#define int long long
typedef unsigned long long ull;
const int mxn = 2e4;
const ll p[4] = {2, 3, 5, 7};
int n, mx = 0, t = 0;
string no;
struct th{
int nxt[26] = {};
};
th trie[mxn * 21];
bool spe[mxn * 21];
void add(string s){
int nd = 0;
for(int i = 0; i < s.size(); i++){
int c = s[i] - 'a';
if(trie[nd].nxt[c] == 0)trie[nd].nxt[c] = ++t;
nd = trie[nd].nxt[c];
}
}
void find(string s){
int nd =0;
for(int i = 0; i < s.size(); i++){
int c = s[i] - 'a';
if(trie[nd].nxt[c] == 0)trie[nd].nxt[c] = ++t;
nd = trie[nd].nxt[c]; spe[nd] = true;
}
}
void dfs(int s){
bool leaf = true;
for(int i = 0; i < 26; i++){
int v = trie[s].nxt[i];
if(!spe[v] && v){
leaf = false;
cout << (char)(i + 'a') << "\n";
dfs(v);
}
}
for(int i = 0; i < 26; i++){
int v = trie[s].nxt[i];
if(spe[v] && v){
leaf = false;
cout << (char)(i + 'a') << "\n";
dfs(v);
}
}
if(leaf)cout << 'P' << "\n";
if(!spe[s])cout << '-' << "\n";
}
signed main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n;
spe[0] = true;
forr(i, 0, n){
string s; cin >> s;
add(s);
if(s.size() > mx){
mx = s.size(); no = s;
}
}
find(no);
dfs(0);
return 0;
}
Compilation message
printer.cpp: In function 'void add(std::string)':
printer.cpp:31:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
31 | for(int i = 0; i < s.size(); i++){
| ~~^~~~~~~~~~
printer.cpp: In function 'void find(std::string)':
printer.cpp:39:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
39 | for(int i = 0; i < s.size(); i++){
| ~~^~~~~~~~~~
printer.cpp: In function 'int main()':
printer.cpp:74:21: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
74 | if(s.size() > mx){
| ~~~~~~~~~^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Expected integer, but "t" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Expected integer, but "e" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
340 KB |
Expected integer, but "h" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Expected integer, but "b" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Expected integer, but "a" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
980 KB |
Expected integer, but "a" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
7 ms |
2900 KB |
Expected integer, but "a" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
25 ms |
7140 KB |
Expected integer, but "a" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
42 ms |
17384 KB |
Expected integer, but "a" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
41 ms |
13644 KB |
Expected integer, but "a" found |
2 |
Halted |
0 ms |
0 KB |
- |