Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- using namespace std;
- int st[20], card[20], n;
- char s[20][20];
- void tipar(int k) {
- for (int i = 1; i <= k; i++)
- cout << s[i][st[i] - 1] << ' ';
- cout << endl;
- }
- int sol(int k) {
- return k == n;
- }
- void bktr() {
- int k = 1;
- st[k] = 0;
- while (k > 0) {
- if (st[k] < card[k]) {
- st[k]++;
- if (sol(k))
- tipar(k);
- else {
- k++;
- st[k] = 0;
- }
- }
- else
- k--;
- }
- }
- int main() {
- cin >> n;
- for (int i = 1; i <= n; i++) {
- cin >> s[i];
- card[i] = strlen(s[i]);
- }
- bktr();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement