Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <set>
- #include <vector>
- using namespace std;
- void outm(vector<string> p) {
- for(long i = 0; i < p.size(); i++) {
- cout << p[i] << " ";
- }
- }
- void f(set<string> &words, set<string> &words1, string s, vector<string> &w) {
- for(long i = s.size(); i > 0; i--) {
- string s1 = s.substr(0, i);
- string s2 = s.substr(1, i - 1);
- if(words.find(s2) == words.end() && words1.find(s1) == words1.end()) {
- w.push_back(s1);
- words.insert(s1);
- if(s2 != "")
- words1.insert(s2);
- }
- }
- }
- int main() {
- long n, k;
- set<string> words, words1;
- vector<string> w;
- vector<long> out;
- string s;
- cin >> n;
- for(long i = 0; i < n; i++) {
- cin >> k;
- for(long j = 0; j < k; j++) {
- cin >> s;
- f(words, words1, s, w);
- }
- outm(w);
- out.push_back(w.size());
- w.clear();
- words.clear();
- words1.clear();
- }
- for(long i = 0; i < out.size(); i++) {
- cout << out[i] << " ";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement