Advertisement
vlatkovski

Short Code (965E) wip

Apr 27th, 2018
334
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.94 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. struct comp
  5. {
  6.     bool operator()(const string &s1, const string &s2)
  7.     {
  8.         return lexicographical_compare(s1.begin(), s1.end(), s2.begin(), s2.end());
  9.     };
  10. };
  11.  
  12. int main()
  13. {
  14.     int n;
  15.     cin >> n;
  16.     set<string, comp> z, z1;
  17.     for (int i = 0; i < n; ++i)
  18.     {
  19.         string s;
  20.         cin >> s;
  21.         z.insert(s);
  22.     }
  23.     int totallen = 0;
  24.     for (auto it = z.begin(); it != z.end(); ++it)
  25.     {
  26.         string s = *it, s1 = "";
  27.         cout << "s = " << s << '\n';
  28.         for (int i = 0; i < s.length(); ++i)
  29.         {
  30.             s1 += s[i];
  31.             cout << "  searching " << s1 << '\n';
  32.             if (z1.find(s1) == z1.end())
  33.             {
  34.                 cout << "    inserting " << s1 << '\n';
  35.                 z1.insert(s1);
  36.                 totallen += i+1;
  37.                 break;
  38.             }
  39.  
  40.         }
  41.     }
  42.     cout << totallen;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement