Cod sursa(job #2743678)

Utilizator AlexCrpCarpineanu Alexandru AlexCrp Data 23 aprilie 2021 13:59:53
Problema Loto Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.99 kb
#include <iostream>
#include <fstream>
#include <unordered_map>

using namespace std;

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

struct elemente
{
	int a, b, c;
};

unordered_map <int, elemente> hashh;
int v[101];
int main()
{
	bool ok = false;
	int n, s,a,suma=0,index=0;

	fin >> n >> s;

	for (int i = 0; i < n; i++)
	{
		fin >> a;
		cout << a << ' ';
		v[index++] = a;
	}

	for (int i = 0; i < n; i++)
	{
		for (int j = i; j < n; j++)
		{
			for (int k = j; k < n; k++)
			{
				suma = v[i] + v[j] + v[k];
				elemente ob;
				ob.a = v[i];
				ob.b = v[j];
				ob.c = v[k];
				hashh[suma] = ob;
			}
		}
	}

	for (auto it : hashh)
	{
		if (hashh.find(s - it.first) != hashh.end())
		{
			fout << hashh[s - it.first].a << ' ' << hashh[s - it.first].b << ' ' << hashh[s - it.first].c << ' ' << it.second.a << ' ' << it.second.b << ' ' << it.second.c;
			ok = true;
			break;
		}
	}

	if (ok == false)
	{
		fout << -1;
	}
	
	return 0;
}