Advertisement
Guest User

Untitled

a guest
Nov 15th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5.  
  6. bool inc(string& s1, string& s2) {
  7. if (s2.size() > s1.size()) return false;
  8. if (s2.size() == s1.size()) return s2 == s1;
  9. for (int i = 0; i < s1.size() - s2.size() + 1; i++) {
  10. if (s1[i] == s2[0]) {
  11. bool found = true;
  12. for (int j = 1; j < s2.size() and found; j++) found = s1[i+j] == s2[j];
  13. if (found) return true;
  14. }
  15. }
  16. return false;
  17. }
  18.  
  19. int main() {
  20. int n;
  21. cin >> n;
  22. vector<string> v(n);
  23. for (int i = 0; i < n; i++) cin >> v[i];
  24. for (int i = 0; i < n; i++) {
  25. cout << v[i] << ':';
  26. for (int j = 0; j < n; j++) if (inc(v[i], v[j])) cout << ' ' << v[j];
  27. cout << endl;
  28. }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement