Cod sursa(job #2116140)

Utilizator SburlyAndrei Florin Sburly Data 27 ianuarie 2018 12:52:37
Problema Loto Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.56 kb
/********************
    Created by Sburly
********************/
#include <iostream>
#include <fstream>
#include <unordered_map>

using namespace std;

unsigned int n;
unsigned long int v[100], s;

struct triple{
    unsigned long a, b, c;

    triple(){}

    triple(const unsigned long int& a, const unsigned long int& b, const unsigned long int& c)
    {
        this->a=a;
        this->b=b;
        this->c=c;
    }

    triple(const triple& other)
    {
        this->a=other.a;
        this->b=other.b;
        this->c=other.c;
    }

    triple operator=(const triple& other)
    {
        this->a=other.a;
        this->b=other.b;
        this->c=other.c;
    }
};
typedef std::unordered_map<unsigned long, triple > hmap;
hmap m;

int main()
{
    ios_base::sync_with_stdio(false);
    ifstream f("loto.in");
    ofstream g("loto.out");

    f >> n >> s;
    for(unsigned int i = 0; i < n; i++)
        f >> v[i];

    for(int i = 0; i < n; i++)
        for(int j = 0; j < n; j++)
            for(int k = 0; k < n; k++)
            {
                triple tmp(v[i],v[j],v[k]);
                unsigned long int sum = v[i]+v[j]+v[k];
                m[sum] = tmp;
                hmap::iterator it = m.find(s-v[i]-v[j]-v[k]);
                if(it != m.end())
                {
                    g << v[i] << ' ' << v[j] << ' ' << v[k] << ' ' << (*it).second.a << ' ' << (*it).second.b << ' ' << (*it).second.c << '\n';
                    return 0;
                }

            }
    g << -1;

    return 0;
}