-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
45 lines (40 loc) · 985 Bytes
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <iostream>
#include <vector>
#include <sstream>
#include <unordered_set>
using namespace std;
/**
* @see https://leetcode.com/explore/challenge/card/march-leetcoding-challenge-2021/588/week-1-march-1st-march-7th/3662/
*/
class Solution {
public:
int minimumLengthEncoding(vector<string>& words) {
int ans = 0;
unordered_set<string> us(words.begin(), words.end());
for (string word : us) {
for(int i = 1; i < word.size(); ++i) {
us.erase(word.substr(i));
}
}
for (string word : us) ans += word.size() + 1;
return ans;
}
};
template <class T>
vector<T> write_vector(vector<T> &v, string &temp, istringstream &ss) {
while (ss >> temp)
v.push_back(temp);
return v;
}
int main() {
string line;
vector<string> words;
string temp;
getline(cin, line);
istringstream ss(line);
words = write_vector(words, temp, ss);
Solution sol;
int r = sol.minimumLengthEncoding(words);
cout << r << endl;
return 0;
}