dev/c/sum_K_O_n/sum_k_o_n.c

28 lines
650 B
C

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int input[] = {5,1,8,6,9,2,44,3,31,26,36,47,51,72,88,7,4};
int N=sizeof(input)/sizeof(int);
int K = 10;
void print_pair(int *input,int K) {
int *mem=alloca(sizeof(int)*K);
int t,i;
memset(mem,0,sizeof(int)*K);
for(t=0;t<N;t++) {
i=input[t];
if (i<=0 || i>=K) continue;
if (mem[K-i]!=0) {
printf("%d %d\n",i,K-i);
mem[K-i]=0;
} else
mem[i]=1;
}
}
int main() {
print_pair(input,K);
return 0;
}