Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define forsn(i, s, n) for(int i=s;i<int(n);i++)
- #define forn(i, n) forsn(i, 0, n)
- #define all(v) v.begin(), v.end()
- #define rall(v) v.rbegin(), v.rend()
- #define NACHO ios_base::sync_with_stdio(0);cin.tie(NULL);
- typedef long long tint;
- struct Trie{
- map<char, Trie> arbol;
- bool finPalabra = false;
- };
- bool encontrado = 1;
- string s;
- int tamPalabra;
- void insertar(Trie &t, int pos) {
- if(pos < tamPalabra){
- if(pos == tamPalabra-1) t.finPalabra = true;
- insertar(t.arbol[s[pos]], pos+1);
- }
- }
- bool consistent = 1;
- void recorrer(Trie t, string palabra){
- if(t.finPalabra && t.arbol.size() > 0){ consistent = 0; cout << palabra << endl;}
- for(auto &i:t.arbol) {
- recorrer(i.second, palabra+i.first);
- }
- }
- int main(){
- int n; cin >> n;
- Trie t;
- vector<string> strs (n);
- forn(i, n){
- cin >> s;
- strs[i] = s;
- tamPalabra = int(s.size())+1;
- insertar(t, 0);
- }
- recorrer(t, "");
- cout << consistent << "\n";
- }
- //
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement