Pagini recente » Cod sursa (job #695455) | Cod sursa (job #1161419) | Cod sursa (job #461204) | Cod sursa (job #583125) | Cod sursa (job #1222178)
#include <stdio.h>
#define NMAX 101
#define HASH_SIZE 666013
#define llong long long
using namespace std;
struct three {
three(int zero, int one, int two) {
this->zero = zero;
this->one = one;
this->two = two;
}
three() {
this->zero = 0;
this->one = 0;
this->two = 0;
}
llong get_sum() {
llong sum = 0;
sum += zero + one + two;
return sum;
}
int zero, one, two;
};
int numbers[NMAX];
struct hash_node {
llong key;
three value;
hash_node *next;
};
hash_node* hash_table[HASH_SIZE] = { NULL };
hash_node* get(llong key) {
hash_node *element = hash_table[key % HASH_SIZE];
while(element != NULL && element->key != key) {
element = element->next;
}
return element;
}
void put(llong key, three value) {
if (get(key) != NULL) return;
hash_node *element = hash_table[key % HASH_SIZE];
hash_node *new_element = new hash_node;
new_element->key = key;
new_element->value = value;
new_element->next = element;
hash_table[key % HASH_SIZE] = new_element;
}
int main() {
freopen("loto.in", "rt", stdin);
freopen("loto.out", "wt", stdout);
llong n, s;
scanf("%lld %lld\n", &n, &s);
for (int i = 0; i < n; i++) {
scanf("%d", &numbers[i]);
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
for (int k = 0; k < n; k++) {
three element(numbers[i], numbers[j], numbers[k]);
put(element.get_sum(), element);
hash_node* other = get(s - element.get_sum());
if (other != NULL) {
printf("%d %d %d %d %d %d\n", other->value.zero, other->value.one, other->value.two, element.zero, element.one, element.two);
return 0;
}
}
}
}
printf("%d\n", -1);
return 0;
}