Cod sursa(job #2092058)

Utilizator Andrei_CotorAndrei Cotor Andrei_Cotor Data 20 decembrie 2017 21:33:35
Problema Loto Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.99 kb
#include<fstream>
#include<tr1/unordered_map>
using namespace std;
using namespace tr1;
ifstream fi("loto.in");
ofstream fo("loto.out");
typedef struct emilutz{int x,y,z;} EMILUTZ;
unordered_map<int,EMILUTZ> H;
EMILUTZ aux;
int n,x,i,j,k,s,A[101];
int main()
{
    fi>>n>>s;
    for(i=1; i<=n; i++)
    {
        fi>>A[i];
    }
    for(i=1; i<=n; i++)
    {
        for(j=1; j<=n; j++)
        {
            for(k=1; k<=n; k++)
            {
                aux.x=A[i];
                aux.y=A[j];
                aux.z=A[k];
                H[A[i]+A[j]+A[k]]=aux;
                if(H.count(s-A[i]-A[j]-A[k])>0)
                {
                    aux=H[s-A[i]-A[j]-A[k]];
                    fo<<A[i]<<" "<<A[j]<<" "<<A[k]<<" "<<aux.x<<" "<<aux.y<<" "<<aux.z<<"\n";
                    fi.close();
                    fo.close();
                    return 0;
                }
            }
        }
    }
    fo<<"-1";
    fi.close();
    fo.close();
    return 0;
}