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 node {
- node* next[26];
- short int strings;
- node() {
- for (int i = 0; i < 26; i++) {
- next[i] = nullptr;
- }
- strings = 0;
- }
- };
- node* root = new node();
- void add(string s) {
- node* curv = root;
- for (int i = 0; i < len(s); ++i) {
- char c = s[i];
- if (curv->next[c - 'a'] == nullptr) {
- curv->next[c - 'a'] = new node();
- }
- curv = curv->next[c - 'a'];
- }
- curv->strings++;
- }
- vector<int> c;
- string s;
- string ans = "";
- string cur_str = "";
- int curi = 0;
- void write(node* v = root) {
- for (int i = 0; i < v->strings; i++) {
- /*while (s[curi] == '.') {
- ans += '.';
- ++curi;
- }
- ans += cur_str;
- while (s[curi] != '.') ++curi;*/
- cout << cur_str;
- cout << string(c[curi], '.');
- curi++;
- }
- for (int i = 0; i < 26; i++) {
- if (v->next[i] != nullptr) {
- cur_str.push_back('a' + i);
- write(v->next[i]);
- cur_str.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;*/
- 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();
- }
- 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