Mai intai trebuie sa te autentifici.
Cod sursa(job #1284284)
Utilizator | Data | 6 decembrie 2014 13:46:45 | |
---|---|---|---|
Problema | Loto | Scor | 70 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 1.26 kb |
#include<fstream>
#include<algorithm>
#include<map>
#include<vector>
#include<cstring>
#include<iterator>
using namespace std;
int n,i,j,k,rez,sum,temp;
int a[105];
map<int,int>mymap;
vector<vector<int> >v;
vector<int>b;
map<int,int> :: iterator it,T;
int main()
{
ifstream f("loto.in");
ofstream g("loto.out");
f>>n>>sum;
for (i=1;i<=n;i++)
f>>a[i];
b.push_back(0),b.push_back(0),b.push_back(0);
for (i=1;i<=n;i++)
for(j=1;j<=n;j++)
for(k=1;k<=n;k++)
{
temp=a[i]+a[j]+a[k];
if (!mymap[temp])
{
b[0]=a[i];
b[1]=a[j];
b[2]=a[k];
v.push_back(b);
mymap[temp]=v.size()-1;
}
}
for(it=mymap.begin();it!=mymap.end();++it)
{
temp=sum-it->first;
T=mymap.find(temp);
if (T!=mymap.end())
{
g<<v[it->second][0]<<" "<<v[it->second][1]<<" "<<v[it->second][2]<<" ";
g<<v[T->second][0]<<" "<<v[T->second][1]<<" "<<v[T->second][2]<<"\n";
return 0;
}
}
g<<"-1\n";
return 0;
}