Cod sursa(job #2895322)

Utilizator urluconceptualCiocan Alexandra-Diana urluconceptual Data 28 aprilie 2022 22:12:32
Problema Loto Scor 45
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1 kb
#include <iostream>
#include <fstream>
#include <unordered_map>

using namespace std;

struct grup {
	int i, j, k;
};

int main()
{
	ifstream fin("loto.in");
	ofstream fout("loto.out");

	int nr, suma, * v, s, gasit=0;
	unordered_map <int, grup> bilet;
	fin >> nr >> suma;
	v = new int[nr];
	for (int i = 0; i < nr; i++) {
		fin >> v[i];
	}
	for (int i = 0; i < nr; i++)
		for (int j = i; j < nr; j++)
			for (int k = j; k < nr; k++) {
				grup x;
				x.i = v[i];
				x.j = v[j];
				x.k = v[k];
				s = x.i + x.j + x.k;
				bilet[s] = x;
			}
	for (auto itr1 = bilet.begin(); itr1 != bilet.end() && gasit == 0; itr1++)
		for (auto itr2 = bilet.begin(); itr2 != bilet.end(); itr2++) {
			if ((itr1->first) + (itr2->first) == suma) {
				fout << (itr1->second).i << " " << (itr1->second).j << " " << (itr1->second).k << " " << (itr2->second).i << " " << (itr2->second).j << " " << (itr2->second).k;
				gasit = 1;
			}
		}
	if (!gasit)
		fout << -1;

	fin.close();
	fout.close();
}