Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- void escriure(vector<char>& v) {
- for (int i = 0; i < v.size(); ++i) {
- cout << v[i];
- }
- cout << endl;
- }
- bool condicions(vector<pair<char, bool> >& c, vector<char>& v, int it) {
- if (it != 0) {
- for (int i = 0; i < v.size(); ++i) {
- if (c[i].first == v[it]) {
- if (v[it-1] == c[i-1].first)
- return false;
- }
- }
- }
- return true;
- }
- void paraulesprohibides(vector<pair<char, bool> >& c, vector<char>& v, int it) {
- if (it == v.size()) escriure(v);
- else if (not condicions(c,v, it-1)) return;
- else {
- for (int i = 0; i < v.size(); ++i) {
- if (not c[i].second) {
- c[i].second = true;
- v[it] = c[i].first;
- paraulesprohibides(c,v,it+1);
- c[i].second = false;
- }
- }
- }
- }
- int main() {
- vector<pair<char, bool> > c (9);
- c[0].first = 'a'; c[0].second = false;
- c[1].first = 'b'; c[1].second = false;
- c[2].first = 'c'; c[2].second = false;
- c[3].first = 'd'; c[3].second = false;
- c[4].first = 'e'; c[4].second = false;
- c[5].first = 'f'; c[5].second = false;
- c[6].first = 'g'; c[6].second = false;
- c[7].first = 'h'; c[7].second = false;
- c[8].first = 'i'; c[8].second = false;
- int n; cin >> n;
- vector<char> v(n);
- paraulesprohibides(c,v,0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement