Cod sursa(job #2746430)

Utilizator Virgil993Virgil Turcu Virgil993 Data 27 aprilie 2021 21:13:33
Problema Loto Scor 85
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.37 kb
#include <iostream>
#include<bits/stdc++.h>
#include<fstream>

using namespace std;

ifstream fin("loto.in");
ofstream fout("loto.out");

struct suma_trei
{
    int a;
    int b;
    int c;
};

unordered_map<int, suma_trei> mp;
unordered_map<int,suma_trei>::iterator it;
unordered_map<int,suma_trei>::iterator it2;

int main()
{

    vector<int> v;
    int n, s;
    fin>>n>>s;
    for(int i=0;i<n;i++)
    {
        int x;
        fin>>x;
        v.push_back(x);
    }
    //memoram toate sumele posibile cu 3 elemente
    for(int i=0;i<v.size();i++)
        for(int j=0;j<v.size();j++)
            for(int k=0;k<v.size();k++)
    {
        int suma_curenta;
        suma_trei t;
        suma_curenta = v[i] + v[j] + v[k];
        t.a = v[i];
        t.b = v[j];
        t.c = v[k];
        if(mp.find(suma_curenta) == mp.end())
            mp[suma_curenta] = t;
        else
            continue;

    }
    int ok = 0;
    for(it2 = mp.begin();it2!=mp.end();it2++)
    {
        it = mp.find(s - it2 -> first);
        if(it != mp.end())
        {

            suma_trei t1,t2;
            t1 = it -> second;
            t2 = it2 -> second;
            fout<<t1.a<<" "<<t1.b<<" "<<t1.c<<" "<<t2.a<<" "<<t2.b<<" "<<t2.c<<" ";
            ok = 1;
            break;
        }
    }
    if(ok == 0)
        fout<<-1;

    return 0;
}