Advertisement
STANAANDREY

prodcart cuv

Nov 3rd, 2020 (edited)
1,935
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.73 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4. int st[20], card[20], n;
  5. char s[20][20];
  6.  
  7. void tipar(int k) {
  8.     for (int i = 1; i <= k; i++)
  9.         cout << s[i][st[i] - 1] << ' ';
  10.     cout << endl;
  11. }
  12.  
  13. int sol(int k) {
  14.     return k == n;
  15. }
  16.  
  17. void bktr() {
  18.     int k = 1;
  19.     st[k] = 0;
  20.     while (k > 0) {
  21.         if (st[k] < card[k]) {
  22.             st[k]++;
  23.             if (sol(k))
  24.                 tipar(k);
  25.             else {
  26.                 k++;
  27.                 st[k] = 0;
  28.             }
  29.         }
  30.         else
  31.             k--;
  32.     }
  33. }
  34.  
  35. int main() {
  36.     cin >> n;
  37.     for (int i = 1; i <= n; i++) {
  38.         cin >> s[i];
  39.         card[i] = strlen(s[i]);
  40.     }
  41.     bktr();
  42.     return 0;
  43. }
  44.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement