Pagini recente » Cod sursa (job #534730) | Cod sursa (job #2961156) | Cod sursa (job #1775475) | Cod sursa (job #2523372) | Cod sursa (job #1209232)
#include <stdio.h>
#define MAXN 100
#define MAXN3 1000000
#define MOD 666013
int v[MAXN];
int hasha[MAXN3 + 1], hashb[MAXN3 + 1], hashc[MAXN3 + 1], next[MAXN3 + 1], dr = 1;
int ult[MOD];
void add(int a, int b, int c){
int poz = (a + b + c) % MOD;
hasha[dr] = a; hashb[dr] = b; hashc[dr] = c;
next[dr] = ult[poz];
ult[poz] = dr;
dr++;
return ;
}
char apare(FILE *out, int s, int a, int b, int c){
int diff = s - a- b - c;
int poz = ult[diff % MOD];
while(poz != 0 && hasha[poz] + hashb[poz] + hashc[poz] != diff) poz = next[poz];
if(poz != 0){
fprintf(out, "%d %d %d %d %d %d", hasha[poz], hashb[poz], hashc[poz], a, b, c);
return 1;
}
return 0;
}
int main(){
FILE *in = fopen("loto.in", "r");
int n, s;
fscanf(in, "%d%d", &n, &s);
int i;
for(i = 0; i < n; i++){
fscanf(in, "%d", &v[i]);
}
fclose(in);
FILE *out = fopen("loto.out", "w");
int j, k, gasit = 0;
for(i = 0; i < n && !gasit; i++){
for(j = 0; j < n && !gasit; j++){
for(k = 0; k < n && !gasit; k++){
add(v[i], v[j], v[k]);
if(apare(out, s, v[i], v[j], v[k])) gasit = 1;
}
}
}
if(!gasit) fprintf(out, "-1");
fclose(out);
return 0;
}