Cod sursa(job #305260)

Utilizator cvicentiuCiorbaru Vicentiu Marian cvicentiu Data 16 aprilie 2009 19:21:19
Problema Loto Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.71 kb
#include <stdio.h>
#define MAXN 101
FILE *f = fopen("loto.in","r");
FILE *g = fopen("loto.out","w");
int n,s,v[MAXN];

void citire(){
	fscanf(f, "%d %d", &n, &s);
	for (int i = 1; i <= n; i++)
		fscanf(f,"%d", &v[i]);
	fclose(f);
}

void bubbleSort(int st, int dr){
	bool ok = true;
	int aux;
	do {
		ok = true;
		for (int i = st; i < dr; i++)
			if ( v[i] > v[i + 1] ) {
				aux = v[i];
				v[i] = v[i + 1];
				v[i + 1] = aux;
				ok = false;
			};
	}
	while ( !ok );
		
};

int main (){
	citire();
	bubbleSort(1, n);
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++)
			for (int k = 1; k <= n; k++)
				if (v[i] + v[j] + v[k] == s) fprintf(g,"-1");
	fclose(g);
	return 0;
}