Pagini recente » Cod sursa (job #2249879) | Cod sursa (job #2828427) | Cod sursa (job #220087) | Cod sursa (job #1382191) | Cod sursa (job #2895099)
#include <iostream>
#include <fstream>
using namespace std;
struct structura{
int first;
int second;
int third;
}perechi[1000000];
int main()
{
ifstream f("loto.in");
ofstream g("loto.out");
int n,loto[101],i,j,k,m,suma,s,x;
f>>n>>s;
for(i=0;i<n;i++)
f>>loto[i];
structura st;
//formam sumele de cate 3 elemente si le punem in hash
for(i=0;i<n;i++)
{
for(j=i;j<n;j++)
{
for(k=j;k<n;k++)
{ suma=0;
st.first = loto[i];
st.second = loto[j];
st.third = loto[k];
suma=loto[i]+loto[j]+loto[k];
perechi[suma]=st;
}
}
}
for(i=0;i<n;i++)
{
for(j=i;j<n;j++)
{
for(k=j;k<n;k++)
{
//cautam diferentele pentru a vedea daca putem ajunge la suma s sau nu
x=(s-loto[i]-loto[j]-loto[k]);
if(perechi[x].first!=0)
{ suma=loto[i]+loto[j]+loto[k]+perechi[x].first+perechi[x].second+perechi[x].third;
if(suma==s)
{
g<<loto[i]<<" "<<loto[j]<<" "<<loto[k]<<" "<<perechi[x].first<<" "<<perechi[x].second<<" "<<perechi[x].third;
return 0;
}
}
}
}
}
g<<-1;
return 0;
}