Advertisement
chunkyguy

Store Credit

Apr 7th, 2011
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.86 KB | None | 0 0
  1. /*
  2.    Problem:  http://code.google.com/codejam/contest/dashboard?c=351101#s=p0
  3.  */
  4.  
  5. #include<stdio.h>
  6. #include<stdlib.h>
  7.  
  8. int main(int argc, char **argv)
  9. {
  10.     int n, c, i, p; //cases, credit, item, price
  11.     int *items = 0;
  12.     int case_no = 1;
  13.     for(scanf("%d",&n); n; n--)
  14.     {
  15.         scanf("%d%d",&c,&i);
  16.         if(items)
  17.             free(items);
  18.         items = (int *)malloc(sizeof(int) * i);
  19.         int a,b; //tmp vats
  20.         for(a = 0; a < i && scanf("%d",&p);a++)
  21.             items[a] = p;
  22.         //process
  23.         int done = 0;
  24.         for(a = 0; a < i && !done; a++)
  25.             for(b = a+1; b < i && !done; b++)
  26.                 if(items[a]+items[b] == c)
  27.                 {
  28.                     printf("Case #%d: %d %d\n",case_no++,a+1,b+1);
  29.                     done = 1;
  30.                 }
  31.     }
  32.   if(items)
  33.       free(items);
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement