Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- struct boi
- {
- string s;
- bool isnew = 0;
- };
- struct comp
- {
- bool operator()(const boi &b1, const boi &b2)
- {
- return lexicographical_compare(b1.s.begin(), b1.s.end(), b2.s.begin(), b2.s.end());
- };
- };
- int main()
- {
- int n;
- cin >> n;
- set<boi, comp> z;
- for (int i = 0; i < n; ++i)
- {
- boi b;
- cin >> b.s;
- z.insert(b);
- }
- int totallen = 0;
- for (auto it = z.begin(); it != z.end(); ++it)
- {
- if (it->isnew) continue;
- string s = it->s, s1 = "";
- for (int i = 0; i < s.length(); ++i)
- {
- s1 += s[i];
- if (z.find(s1) == z.end())
- {
- boi b1;
- b1.s = s1;
- b1.isnew = 1;
- z.insert(b1);
- totallen += i+1;
- break;
- }
- }
- }
- cout << totallen;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement