Created
April 7, 2011 02:24
Revisions
-
Joel Clermont created this gist
Apr 7, 2011 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,64 @@ // // main.c // cj-store-credit // // Created by Joel Clermont on 4/6/11. // Copyright 2011 Orion Group, LLC. All rights reserved. // #include <stdio.h> #include <time.h> int main (int argc, const char * argv[]) { clock_t start = clock(); int N = 0; int C = 0; int l = 0; int caseNum = 0, itemNum = 0; int outer = 0, inner = 0; int lowIndex = 0, highIndex = 0; //open input FILE *input; input = fopen("/Users/joelclermont/Documents/Projects/codejam/cj-store-credit/cj-store-credit/a-small.in", "r"); //open output FILE *output; output = fopen("/Users/joelclermont/Documents/Projects/codejam/cj-store-credit/cj-store-credit/a-small.out", "w"); //get number of cases fscanf(input, "%d", &N); for(caseNum = 0; caseNum < N; caseNum++) { lowIndex = 0; highIndex = 0; fscanf(input, "%d", &C); fscanf(input, "%d", &l); int P[l]; for(itemNum = 0; itemNum < l; itemNum++) { fscanf(input, "%d", &P[itemNum]); } for(outer = 0; outer < l; outer++) { for (inner = outer + 1; inner < l; inner++) { if (P[outer] + P[inner] == C) { lowIndex = outer + 1; highIndex = inner + 1; break; } } if (lowIndex > 0) break; } fprintf(output, "Case #%d: %d %d\n", caseNum + 1, lowIndex, highIndex); } fclose(input); fclose(output); printf("time elapsed: %f\n", ((double)clock() - start)/CLOCKS_PER_SEC); return 0; }