Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <cmath>
- #include <set>
- #include <deque>
- #include <queue>
- #include <algorithm>
- #include <stack>
- #include <map>
- #include <string>
- #include <iomanip>
- #include <fstream>
- #include <unordered_map>
- #define all(v) v.begin(), v.end()
- #define ll long long
- #define ld long double
- #define lb lower_bound
- #define ub upper_bound
- #define len(v) (ll)v.size()
- #define last(v) (ll)v[len(v) - 1]
- using namespace std;
- const ll inf = 1e9;
- const ll MAXN = 1e6 + 1;
- const ll MAXM = 1e5 + 1;
- const int logn = 29;
- template<class T>
- istream& operator>>(istream& in, vector<T>& a) {
- for (auto& i : a)
- in >> i;
- return in;
- }
- template<class T>
- ostream& operator<<(ostream& out, vector<T>& a) {
- for (auto& i : a)
- out << i << " ";
- return out;
- }
- struct vertex {
- map<char, int> next;
- int leaf;
- };
- string s;
- vertex t[MAXN + 1];
- int sz;
- void add(const string& s) {
- int v = 0;
- for (int i = 0; i < len(s); ++i) {
- char c = s[i];
- if (t[v].next[c] == 0) {
- t[v].next[c] = sz++;
- }
- v = t[v].next[c];
- }
- t[v].leaf++;
- }
- vector<int> c;
- int curi = 0;
- string curstr = "";
- void write(vertex v) {
- for (int i = 0; i < v.leaf; ++i) {
- cout << curstr;
- cout << string(c[curi++], '.');
- }
- for (int i = 0; i < 26; ++i) {
- char c = ('a' + i);
- if (v.next[c] != 0) {
- curstr.push_back(c);
- write(t[v.next[c]]);
- curstr.pop_back();
- }
- }
- }
- void solve() {
- /*cin >> s;
- s += '.';
- bool f = 0;
- if (s[0] != '.') f = 1;
- string cur = "";
- for (int i = 0; i < len(s); ++i) {
- if (s[i] == '.' && f) {
- f = 0;
- add(cur);
- cur = "";
- }
- else if (s[i] != '.' && !f) {
- f = 1;
- cur += s[i];
- }
- else if (s[i] != '.' && f) cur += s[i];
- }
- while (s[curi] == '.' && curi < (len(s) - 1)) {
- ans += '.';
- ++curi;
- }
- write();
- while (s[curi] == '.' && curi < (len(s) - 1)) {
- ans += '.';
- ++curi;
- }
- cout << ans;*/
- sz = 1;
- cin >> s;
- string curstr = "";
- int cnt = 0;
- for (int i = 0; i < len(s); ++i) {
- if (s[i] == '.') {
- ++cnt;
- if (curstr.size() > 0) add(curstr);
- //cout << curstr << endl;
- curstr = "";
- } else {
- if (cnt > 0) c.push_back(cnt);
- cnt = 0;
- curstr += s[i];
- }
- }
- if (cnt > 0) c.push_back(cnt);
- if (curstr.size() > 0) {
- add(curstr); //cout << curstr << endl;
- }
- c.push_back(0);
- if (s[0] == '.') cout << string(c[curi++], '.');
- write(t[0]);
- }
- int main() {
- ios::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- solve();
- return 0;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement