Advertisement
Guest User

Untitled

a guest
Sep 24th, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. #include <iostream>
  2. #include <set>
  3. #include <vector>
  4. using namespace std;
  5. void outm(vector<string> p) {
  6. for(long i = 0; i < p.size(); i++) {
  7. cout << p[i] << " ";
  8. }
  9. }
  10. void f(set<string> &words, set<string> &words1, string s, vector<string> &w) {
  11. for(long i = s.size(); i > 0; i--) {
  12. string s1 = s.substr(0, i);
  13. string s2 = s.substr(1, i - 1);
  14. if(words.find(s2) == words.end() && words1.find(s1) == words1.end()) {
  15. w.push_back(s1);
  16. words.insert(s1);
  17. if(s2 != "")
  18. words1.insert(s2);
  19. }
  20. }
  21. }
  22. int main() {
  23. long n, k;
  24. set<string> words, words1;
  25. vector<string> w;
  26. vector<long> out;
  27. string s;
  28. cin >> n;
  29. for(long i = 0; i < n; i++) {
  30. cin >> k;
  31. for(long j = 0; j < k; j++) {
  32. cin >> s;
  33. f(words, words1, s, w);
  34. }
  35. outm(w);
  36. out.push_back(w.size());
  37. w.clear();
  38. words.clear();
  39. words1.clear();
  40. }
  41. for(long i = 0; i < out.size(); i++) {
  42. cout << out[i] << " ";
  43. }
  44. return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement