Advertisement
savrasov

MS-DOS

May 4th, 2017
427
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.99 KB | None | 0 0
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <string>
  4. #include <cstring>
  5.  
  6. typedef long long ll;
  7. typedef unsigned long long ull;
  8. typedef long double ld;
  9. typedef unsigned int uint;
  10.  
  11. using namespace std;
  12.  
  13. string s[20000], ans;
  14. int n, u = 0, o;
  15.  
  16. void check(int r, int t)
  17. {
  18.     string st, s1;
  19.     int y = 0;
  20.     for (int i = 0; i < r; i++)
  21.         st += s[i] + (char)92;
  22.     st += "...";
  23.     st += (char)92;
  24.     for(int i = t; i < n; i++)
  25.         s1 += s[i] + (char)92;
  26.     s1.resize(s1.size() - 1);
  27.     st += s1;
  28.     if (st.size() > o) return;
  29.     if (st.size() > ans.size() || (st.size() == ans.size() && s1.size() > u))
  30.         ans = st, u = s1.size();
  31. }
  32.  
  33. int main()
  34. {
  35.     char c;
  36.     cin >> o;
  37.     while (cin >> c)
  38.     {
  39.         if (c == 92) n++;
  40.         else s[n] += c;
  41.     }
  42.     n++;
  43.     for (int i = 0; i < n; i++) ans += s[i] + (char)92;
  44.     ans.resize(ans.size() - 1);
  45.     if (o >= ans.size()) return cout << ans, 0;
  46.     ans = "";
  47.     for (int i = 2; i < n - 1; i++)
  48.         for (int j = i + 1; j < n; j++)
  49.             check(i, j);
  50.     cout << ans;
  51.     return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement