Advertisement
Guest User

Untitled

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