Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- const int ID = 7;
- vector<int> z;
- void zfunc(string s)
- {
- for (int i = 1, l = 0, r = 0; i < s.size(); ++i)
- {
- if (i <= r)
- z[i] = min(z[i - l], r - i + 1);
- while (i + z[i] < s.size() && s[i + z[i]] == s[z[i]])
- ++z[i];
- if (i + z[i] - 1 > r)
- r = i + z[i] - 1, l = i;
- }
- }
- int main()
- {
- // freopen("twi.in", "r", stdin);
- int m;
- cin >> m;
- string s;
- getline(cin, s);
- getline(cin, s);
- string t = "http://!";
- t += s;
- int n = t.size();
- z.resize(n);
- zfunc(t);
- string ans = "";
- int k = max((int)s.size() - m, 0);
- for (int i = ID + 1; i < n; ++i)
- {
- if (z[i] >= ID && t[i + z[i]] != ' ' && k && (i == ID + 1 || (i > ID + 1) && t[i - 1] == ' '))
- {
- int it = i;
- int cnt = 0;
- bool badbitch = false;
- while(it < n && t[it] != ' ')
- {
- bool small = ('a' <= t[it] && t[it] <= 'z');
- bool fig = ('0' <= t[it] && t[it] <= '9');
- bool dot = (t[it] == '.');
- bool slash = (t[it] == '/');
- bool tdots = (t[it] == ':');
- if (!(small || fig || dot || slash || tdots))
- badbitch = true;
- ++it, ++cnt;
- }
- if (badbitch)
- {
- ans += t[i];
- continue;
- }
- int add = cnt - 3 - min(cnt, k);
- k -= min(cnt - 3, k);
- for (int j = i; j < i + add; ++j)
- ans += t[j];
- ans += "...";
- i = it - 1;
- }
- else
- ans += t[i];
- }
- cout << ans << endl;
- cout << max((int)ans.size() - m, 0) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment