Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <vector>
- #include <list>
- #include <map>
- #include <set>
- #include <deque>
- #include <stack>
- #include <bitset>
- #include <algorithm>
- #include <functional>
- #include <numeric>
- #include <utility>
- #include <sstream>
- #include <iostream>
- #include <fstream>
- #include <string.h>
- #include <iomanip>
- #include <cstdio>
- #include <cmath>
- #include <cstdlib>
- #include <ctime>
- #include <queue>
- #define inf 1000*1000*1000
- #define mod 1000000007
- #define ff first
- #define ss second
- #define mp make_pair
- using namespace std;
- struct vertex {
- int next[309];
- bool leaf;
- };
- vertex t[300009];
- int sz, ind, ans, start = -1;
- char c[300009];
- void add_string (const string & s) {
- int v = 0;
- for (size_t i=0; i<s.length(); ++i) {
- char c = s[i]-'a';
- if (t[v].next[c] == -1) {
- memset (t[sz].next, 255, sizeof t[sz].next);
- t[v].next[c] = sz++;
- }
- v = t[v].next[c];
- }
- t[v].leaf = true;
- }
- void print_tree(int v) {
- for(int i = 0; i<=25; i++) {
- if(t[v].next[i] != -1) {
- cout<<char(i+'a')<<" "<<t[v].leaf<<endl;
- print_tree(t[v].next[i]);
- }
- }
- }
- string in;
- int main() {
- memset (t[0].next, 255, sizeof t[0].next);
- sz = 1;
- while(getline(cin,in)) {
- start = -1;
- cout<<in<<endl;
- for(int i=0;i<in.length();i++)
- {
- c[ind] = in[i];
- ind++;
- }
- for (int i=0;i<in.length();i++) {
- if((in[i]-'a'>=0 && in[i]-'a'<=25)) {
- start = i;
- break;
- }
- }
- if(start != -1) {
- for (int i=start;i<in.length();i++) {
- if(!(in[i]-'a'>=0 && in[i]-'a'<=25) || (in[i] == '\n')) {
- ans++;
- string cur = "";
- for(int j = start; j < i; j++)
- cur += c[j];
- //cout<<cur<<endl;
- add_string(cur);
- start = i + 1;
- }
- }
- }
- }
- print_tree(0);
- cout<<in<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement