Pagini recente » Cod sursa (job #2372443) | Cod sursa (job #1682396) | Cod sursa (job #1776626) | Cod sursa (job #897176) | Cod sursa (job #244785)
Cod sursa(job #244785)
// loto.cpp : Defines the entry point for the console application.
//
#include <stdio.h>
#include <stdlib.h>
int e[104];
int f[7];
int comparare (const void * a, const void * b)
{
return ( *(int*)a - *(int*)b );
}
int main()
{
int n,suma,i,maxnr,numere=6;
FILE *f1,*f2;
f1=fopen("loto.in","r");
f2=fopen("loto.out","w");
fscanf(f1,"%d %d",&n,&suma);
for(i=1;i<=n;i++)
fscanf(f1,"%d",&e[i]);
qsort(e,n+1,sizeof(int),comparare);
if(e[n]*6>suma)
{
fprintf(f2,"-1");
fclose(f1);
fclose(f2);
return 0;
}
maxnr=e[n];
while(suma-numere>maxnr)
{
f[numere]=maxnr;
numere--;
suma=suma-maxnr;
}
for(i=numere-1;i>0;i--)
{
e[i]=1;
suma--;
}
f[numere]=suma;
for(i=1;i<=6;i++)
fprintf(f2,"%d ",e[i]);
fclose(f1);
fclose(f2);
return 0;
}