Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- const int k = 26;
- const int maxn = 15e5;
- struct vert{
- int flag = 0;
- int go[k];
- };
- vert g[maxn];
- int all = 1;
- void addstr(string s){
- int v = 0;
- for(int i = 0; i < s.size(); i++){
- int to = s[i] - 'a';
- if(g[v].go[to] == -1){
- g[v].go[to] = all++;
- for(int q = 0; q < k; q++){
- g[all-1].go[q] = -1;
- }
- }
- v = g[v].go[to];
- }
- g[v].flag++;
- }
- string cur;
- vector<string> sortedans;
- void print(int v){
- for(int i = 0; i < g[v].flag; i++){
- sortedans.push_back(cur);
- }
- for(int i = 0; i < k; i++){
- if(g[v].go[i] != -1){
- cur.push_back(i + 'a');
- print(g[v].go[i]);
- cur.pop_back();
- }
- }
- }
- signed main(){
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- string s;
- cin>>s;
- for(int q = 0; q < k; q++){
- g[0].go[q] = -1;
- }
- vector<int> points;
- int row = 0;
- for(int i = 0; i < s.size();){
- if(s[i] == '.'){
- row++;
- i++;
- }
- else{
- points.push_back(row);
- row = 0;
- int len = 0;
- while(i < s.size() && s[i] != '.'){
- i++;len++;
- }
- addstr(s.substr(i - len, len));
- }
- }
- points.push_back(row);
- print(0);
- for(int i = 0; i < points.size(); i++){
- for(int j = 0; j < points[i]; j++){
- cout<<'.';
- }
- if(i < sortedans.size())cout<<sortedans[i];
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement