Pagini recente » Cod sursa (job #2626225) | Cod sursa (job #2864888) | Cod sursa (job #2577987) | Cod sursa (job #3217606) | Cod sursa (job #130518)
Cod sursa(job #130518)
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
using namespace std;
class ThreeTuple {
public:
int v[3];
};
int S(0),
N(0),
v[100];
int main(int argc, char *argv[]) {
ifstream fin("loto.in");
fin >> N >> S;
for (int i(0); i < N; ++i)
fin >> v[i];
fin.close();
map<int, ThreeTuple> sume;
ThreeTuple aux;
for (int i(0); i < N; ++i) {
aux.v[0] = v[i];
for (int j(0); j < N; ++j) {
aux.v[1] = v[j];
for (int k(0); k < N; ++k) {
aux.v[2] = v[k];
if (sume.count(v[i] + v[j] + v[k]) == 0) {
sume.insert(pair<int, ThreeTuple>(v[i] + v[j] + v[k], aux));
}
}
}
}
for (map<int, ThreeTuple>::const_iterator it = sume.begin(); it != sume.end(); ++it)
if (sume.count(S - it->first)) {
ofstream fout("loto.out");
aux = sume[S - it->first];
fout << it->second.v[0] << " " << it->second.v[1] << " " << it->second.v[2] << " "
<< aux.v[0] << " " << aux.v[1] << " " << aux.v[2] << endl;
fout.close();
return 0;
}
ofstream fout("loto.out");
fout << -1 << endl;
fout.close();
return 0;
}