Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- using namespace std;
- int n = 5, card[20], st[20], nrsol;
- char alfa[7][30], v[] = "AEIOU";
- void init() {
- for (int i = 0; i < int('Z' - 'A' + 1); i++)
- alfa[1][i] = char(i + 'A');
- card[1] = strlen(alfa[1]);
- for (int i = 2; i <= n; i++) {
- strcpy(alfa[i], alfa[1]);
- card[i] = card[1];
- }
- }
- int valid(int k) {
- if (k > 1 && strchr(v, alfa[k][st[k] - 1]) && strchr(v, alfa[k - 1][st[k - 1] - 1]))
- return 0;
- return 1;
- }
- int sol(int k) {
- return k == n;
- }
- void tipar(int k) {
- nrsol++;
- for (int i = 1; i <= k; i++)
- cout << alfa[i][st[i] - 1];
- cout << '\n';
- }
- void bktr() {
- int k = 1;
- st[k] = 0;
- while (k > 0) {
- if (st[k] < card[k]) {
- st[k]++;
- if (valid(k)) {
- if (sol(k))
- tipar(k);
- else {
- k++;
- st[k] = 0;
- }
- }
- }
- else
- k--;
- }
- }
- int main() {
- init();
- bktr();
- cout << nrsol;
- return 0;
- }
Add Comment
Please, Sign In to add comment