Pagini recente » Cod sursa (job #2289197) | Cod sursa (job #2227892) | Cod sursa (job #1590568) | Cod sursa (job #1672933) | Cod sursa (job #779930)
Cod sursa(job #779930)
//Include
#include <fstream>
#include <set>
using namespace std;
//Structuri
struct mystr
{
int value;
int first, second, third;
}newElement, searched;
struct compare
{
bool operator() (mystr a, mystr b)
{ return a.value < b.value; }
};
//Variabile
ifstream in("loto.in");
ofstream out("loto.out");
int eNum, sum;
int numbers[101];
set<mystr, compare> sums;
set<mystr, compare>::iterator it1, it2, end;
//Main
int main()
{
in >> eNum >> sum;
for(int i=1 ; i<=eNum ; ++i)
in >> numbers[i];
for(int i=1 ; i<=eNum ; ++i)
for(int j=i ; j<=eNum ; ++j)
for(int k=j ; k<=eNum ; ++k)
{
newElement.value = (newElement.first = numbers[i]) + (newElement.second = numbers[j]) + (newElement.third = numbers[k]);
sums.insert(newElement);
}
end = sums.end();
for(it1=sums.begin() ; it1!=end ; ++it1)
{
searched.value = sum - it1->value;
if((it2 = sums.find(searched)) != end)
{
out << it1->first << ' ' << it1->second << ' ' << it1->third << ' ' << it2->first << ' ' << it2->second << ' ' << it2->third << '\n';
in.close();
out.close();
return 0;
}
}
out << -1 << '\n';
in.close();
out.close();
return 0;
}