Store credit problem: why my solution did no good. my code is:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>



int *result(int tab[], int nitem, int credit){
int i, j;
int result[2];
for(i=0; i<nitem; i++){
for(j=i+1; j<nitem; j++){
if(tab[i]+tab[j]== credit){
result[0]= i;
result[1]= j;
printf("%d %d   \n",tab[i], tab[j]);
return result;
}
}
}
return NULL;
}


int main(void) {
FILE * fin, *fout;
int i, j;
int *tabitem;
int *solution;
int credit, nitem,totalCases=0;
fin = fopen("A-small.in", "r");
fout = fopen("output.in", "w");
fscanf(fin, "%d", &totalCases);
for (i=0;i<totalCases;i++){
//printf()
fscanf(fin, "%d",&credit);
fscanf(fin, "%d",&nitem);
tabitem =(int*) malloc((sizeof(int))* nitem);
for(j=0; j<nitem; j++){
fscanf(fin, "%d",&tabitem[j]);
}
solution = (int*) malloc((sizeof(int))*2);
solution = result(tabitem, nitem, credit);
fprintf(fout, "Case #%d: %d %d\n",i+1,solution[0]+1, solution[1]+1);
//fprintf(fout, "Case #%d: %d %d               Credit = %d          nombre
item = %d \n",i+1,solution[0]+1, solution[1]+1, credit, nitem);
free (solution);
free (tabitem);
}
fclose (fin);
fclose (fout);
return EXIT_SUCCESS;
}



my solution is:

Case #1: 2 3
Case #2: 1 4
Case #3: 4 5
Case #4: 19 95
Case #5: 42 43
Case #6: 32 33
Case #7: 18 44
Case #8: 21 22
Case #9: 4 34


-- 
Nzouwo bernis.
PhD candidat in Computer Science.
Cisco course in CCNA
Tel:(00237)75282421
Hobby: Sport, Chess game, Music.

-- 
You received this message because you are subscribed to the Google Groups 
"google-codejam" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-code?hl=en.

Reply via email to