sum_k_o_n.c

This commit is contained in:
Kolan Sh 2011-12-13 13:02:39 +03:00
parent ee2ff52879
commit ccf623eeb7
1 changed files with 27 additions and 0 deletions

27
c/sum_K_O_n/sum_k_o_n.c Normal file
View File

@ -0,0 +1,27 @@
#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;
}