Pagini recente » Cod sursa (job #1881731) | Cod sursa (job #1723998) | Cod sursa (job #2285061) | Cod sursa (job #618328) | Cod sursa (job #1071475)
#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;
}