Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <algorithm>
- #include <iostream>
- #include <memory.h>
- #include <iterator>
- #include <cassert>
- #include <fstream>
- #include <iomanip>
- #include <cstdlib>
- #include <bitset>
- #include <vector>
- #include <cstdio>
- #include <string>
- #include <queue>
- #include <deque>
- #include <cmath>
- #include <ctime>
- #include <stack>
- #include <set>
- #include <map>
- using namespace std;
- //#define int long long
- #define fi first
- #define se second
- #define pb push_back
- #define mp make_pair
- #define all(x) x.begin() , x.end()
- typedef long long ll;
- typedef long double ld;
- typedef pair < ll , ll > pll;
- typedef pair < int , int > pii;
- template < typename T >
- T read(){
- T p = 1 , x = 0;
- char s = getchar();
- while(s == ' ' || s == '\n') s = getchar();
- if(s == '-') p = -1 , s = getchar();
- while(s >= '0' && s <= '9'){
- x = x * 10 + s - '0';
- s = getchar();
- }
- return x * p;
- }
- template < typename A , typename B >
- void Umax(A &a , const B &b){
- if(a < b)
- a = b;
- }
- template < typename A , typename B >
- void Umin(A &a , const B &b){
- if(a > b){
- a = b;
- }
- }
- ll bin_pow (ll a , ll n) {
- if(n == 0){
- return 1;
- }
- if(n % 2 == 1){
- ll cnt = a * bin_pow(a , n - 1);
- return cnt;
- }
- else {
- ll cnt = bin_pow(a , n / 2);
- return cnt * cnt;
- }
- }
- const int N = (int) 1e5 + 10;
- const int MOD = (int) 1e9 + 7;
- const int INF = (int) 1e9 + 10;
- const ll LLINF = (ll) 1e18 + 10;
- const int dx [] = { 0 , 0 , 1 , -1 };
- const int dy [] = { 1 , -1 , 0 , 0 };
- ll ans = 0, cnt = 1;
- vector <string> s;
- pair <int, int > trie[3 * N][26];
- void add(string val) {
- int v = 1;
- for(int i = 0; i < val.size(); ++i) {
- int f = static_cast<int>(val[i]) - 97;
- if(trie[v][f].fi == 0) {
- trie[v][f].fi = ++cnt;
- trie[v][f].se++;
- } else {
- trie[v][f].se++;
- }
- v = trie[v][f].fi;
- }
- }
- void get(string val) {
- int v = 1;
- for(int i = 0; i < val.size(); ++i) {
- int f = static_cast<int>(val[i]) - 97;
- if(trie[v][f].se > 1) {
- cout << val[i];
- ans++;
- } else {
- cout << val[i];
- ans++;
- return;
- }
- v = trie[v][f].fi;
- }
- }
- int main ()
- {
- freopen("input.txt" , "r" , stdin);
- freopen("output.txt" , "w" , stdout);
- ios_base::sync_with_stdio(false);
- char ch;
- string currS= "";
- while((ch = getchar()) != EOF) {
- if(ch >= 'a' && ch <= 'z') {
- currS += ch;
- } else {
- if(currS.size() > 0) {
- s.pb(currS);
- add(currS);
- currS = "";
- }
- ans++;
- }
- }
- for(int i = 0; i < s.size(); ++i) {
- get(s[i]);
- cout << endl;
- }
- cout << ans << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement