csansoon

P7.11 P29428 F002A. Infixes

Nov 14th, 2018
1,043
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.79 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. using namespace std;
  5.  
  6. bool contains(string s1, string s2)
  7. {
  8.     int i = 0;
  9.     bool last_check = false;
  10.    
  11.     while(i < s1.length() and not last_check)
  12.     {
  13.         int j = 0;
  14.         bool check = true;
  15.         while(j < s2.length() and check)
  16.         {
  17.             check = true;
  18.             if(s1[i+j] != s2 [j]) check = false;
  19.             ++j;
  20.             last_check = check;
  21.         }
  22.         ++i;
  23.     }
  24.     return last_check;
  25. }
  26.  
  27. int main()
  28. {
  29.     int n;
  30.     cin >> n;
  31.     vector<string> v(n);
  32.     for(int i = 0; i < n; ++i) cin >> v[i];
  33.    
  34.     for(int i = 0; i < n; ++i)
  35.     {
  36.         cout << v[i] << ":";
  37.         int j = 0;
  38.         while(j < n)
  39.         {
  40.             if(v[i].size() >= v[j].size() and contains(v[i], v[j])) cout << " " << v[j];
  41.             ++j;
  42.         }
  43.         cout << endl;
  44.     }
  45. }
  46.  
  47. // (c) Carlos Sansón (Best pro1 delegate ever for sure) @csansoon
Advertisement
Add Comment
Please, Sign In to add comment