Cod sursa(job #1071475)

Utilizator pinkahdPinca Alexandru Laurentiu pinkahd Data 2 ianuarie 2014 23:46:13
Problema Loto Scor 5
Compilator cpp Status done
Runda Arhiva de probleme Marime 2.15 kb
#include <stdio.h>
#include <math.h>

using namespace std;

int main()
{
    FILE *f;
    int n = 0 ,s = 0;

    f = fopen("loto.in","rt");
    fscanf(f,"%d%d",&n,&s);

    printf("%d \n", s);
    printf("%d \n", n);

    int i, nr[100], s1, s2, a,b,c,stop;

    for (i=0; i<n; i++)
        fscanf(f,"%d",&nr[i]);

    fclose(f);

    if (s%2 == 0)
    {
        s1 = s / 2;
        s2 = s / 2;
    }
    else
    {
        s1 = round(s / 2);
        if (s1 + round(s / 2) + 1 == s)
            s2 = round(s / 2) + 1;
        else
            s2 = round(s / 2) - 1;
    }

    printf("%d %d", s1, s2);

    f = fopen("loto.out","wt");
    stop = 0;
    for (a=0; a<n; a++)
        if (stop == 0)
            for (b=0; b<n; b++)
                if (stop == 0)
                    for (c=0; c<n; c++)
                        if (stop == 0)
                            if (nr[a] + nr[b] + nr[c] == s1)
                            {
                                printf("%d %d %d ", nr[a], nr[b], nr[c]);
                                fprintf(f,"%d %d %d ", nr[a], nr[b], nr[c]);
                                stop = 1;
                                break;
                            }
                        else
                            break;
                else
                    break;
        else
            break;

    stop = 0;
    for (a=0; a<n; a++)
        if (stop == 0)
            for (b=0; b<n; b++)
                if (stop == 0)
                    for (c=0; c<n; c++)
                        if (stop == 0)
                            if (nr[a] + nr[b] + nr[c] == s2)
                            {
                                printf("%d %d %d ", nr[a], nr[b], nr[c]);
                                fprintf(f,"%d %d %d ", nr[a], nr[b], nr[c]);
                                stop = 1;
                                break;
                            }
                        else
                            break;
                else
                    break;
        else
            break;

    if (stop != 1)
        fprintf(f,"-1");

    fclose(f);

    return 0;
}