Pagini recente » Cod sursa (job #409973) | Cod sursa (job #2229417) | Cod sursa (job #2875106) | Cod sursa (job #3040666) | Cod sursa (job #1111412)
//Include
#include <fstream>
#include <set>
using namespace std;
//Structuri
struct mystr
{
int value;
int first, second, third;
}newElement, searched;
//Clase
class compare
{
public:
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, end1;
//Main
int main()
{
in >> eNum >> sum;
for(int i=1 ; i<=eNum ; ++i)
in >> numbers[i];
for(int i=0 ; ++i<=eNum ;)
for(int j=i-1 ; ++j<=eNum ;)
for(int k=j-1 ; ++k<=eNum ;)
{
newElement.value = (newElement.first = numbers[i]) + (newElement.second = numbers[j]) + (newElement.third = numbers[k]);
sums.insert(newElement);
}
end1 = sums.end();
for(it1=sums.begin() ; it1!=end1 ; ++it1)
{
searched.value = sum - it1->value;
if((it2 = sums.find(searched)) != end1)
{
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;
}