Problema 1…. C++
Vă rog!
Răspunsuri la întrebare
1.
#include <iostream>
#include <fstream>
using namespace std;
int m, n, x[101];
char v[101][101];
int ok(int k) {
for (int i = 1; i < = k; i++)
if (x[i] == x[k])
return 0;
return 1;
}
void afis(int k) {
for (int i = 1; i < = k; i++)
cout << v[x[i]] <<" ";
cout << endl;
}
void back(int k) {
for (int i = 1; i < = n; i++) {
x[k] = i;
if (ok(k))
if (k == m)
afis(k);
else
back(k + 1);
}
}
int main() {
ifstream f("date.txt");
f >> n >> m;
f.get();
for (int i = 1; i < = n; i++)
f.getline(v[i], 10);
back(1);
return 0;
}
8.
#include <iostream>
#include <fstream>
using namespace std;
int x[6];
char a[7][10];
int ok(int k) {
if (x[2] ! = 1 && x[2] ! = 3 && x[2] ! = 4)
return 0;
for (int i = 1; i < k; i++)
if (x[k] == x[i])
return 0;
return 1;
}
void afis(int k) {
for (int i = 1; i <= 3; i++)
cout << a[x[i]] << " ";
cout << endl;
}
void back(int k) {
for (int i = 1; i <= 6; i++) {
x[k] = i;
if (ok(k))
if (k == 3)
afis(k);
else
back(k + 1);
}
}
int main() {
ifstream f("date.txt");
for (int i = 1; i < = 6; i++)
f >> a[i];
back(1);
f.close();
return 0;
}