# C Programming : File I/O



## The Conqueror (Dec 22, 2013)

*Problem:*
You receive a credit C at a local store and would like to buy two items. You first walk through the store and create a list L of all available items. From this list you would like to buy two items that add up to the entire value of the credit. The solution you provide will consist of the two integers indicating the positions of the items in your list (smaller number first).
*
Input*

The first line of input gives the number of cases, N. N test cases follow. For each test case there will be:

    One line containing the value C, the amount of credit you have at the store.
    One line containing the value I, the number of items in the store.
    One line containing a space separated list of I integers. Each integer P indicates the price of an item in the store.
    Each test case will have exactly one solution.
*
Output*

For each test case, output one line containing "Case #x: " followed by the indices of the two items whose price adds up to the store credit. The lower index should be output first.
Small dataset

N = 10
3 ≤ I ≤ 100

Large dataset

N = 50
3 ≤ I ≤ 2000 
*
Input*

3
100
3
5 75 25
200
7
150 24 79 50 88 345 3
8
8
2 1 9 4 4 56 90 3
*OUTPUT:*
Case #1: 2 3
Case #2: 1 4
Case #3: 4 5



> ```
> #include <stdio.h>
> #include <stdlib.h>
> int main()
> ...


----------



## harshilsharma63 (Dec 22, 2013)

Make 'p' a dynamic array. How long have you been into programming?


----------



## The Conqueror (Dec 22, 2013)

I have been into programming since high-school but back then it was fairly elementary stuff. I have just recently started diving into algorithmic problem solving by participating on online portals.


Some cases are being printed *multiple *times, so that's why the online judge was saying it contains 66 test cases instead of expected 50.
This is the output file for large dataset.

```
Case #1: 2 3
Case #2: 1 4
Case #3: 4 5
Case #4: 29 46
Case #5: 11 56
Case #6: 84 240
Case #7: 413 584
Case #8: 28 80
Case #9: 380 633
Case #10: 190 242
Case #11: 450 667
Case #12: 7 126
Case #13: 208 636
Case #14: 301 831
[B]Case #15: 243 649
Case #15: 769 1172
Case #15: 865 1172[/B]
Case #16: 258 429
Case #17: 18 49
Case #18: 7 32
Case #19: 750 965
Case #20: 196 718
Case #21: 292 1236
Case #22: 539 935
Case #23: 20 263
Case #24: 30 107
Case #25: 3 94
Case #26: 425 484
[B]Case #27: 135 947
Case #27: 227 947
Case #27: 503 947
Case #27: 623 923[/B]
Case #28: 219 656
Case #28: 739 1178
Case #29: 133 242
Case #29: 173 594
Case #30: 370 824
Case #30: 691 800
Case #30: 735 824
Case #30: 808 824
Case #31: 317 338
Case #32: 207 485
Case #32: 218 919
Case #32: 277 919
Case #33: 63 64
Case #34: 13 206
Case #35: 407 421
Case #36: 654 972
Case #37: 205 275
Case #38: 499 883
Case #39: 471 633
Case #40: 371 393
Case #41: 25 170
Case #42: 64 521
Case #43: 21 80
Case #43: 28 78
Case #44: 949 1590
Case #45: 1 1043
Case #46: 636 773
Case #47: 240 908
Case #47: 1156 1292
Case #47: 1221 1292
Case #48: 6 47
Case #49: 22 318
Case #49: 81 288
Case #50: 274 983
```

I tried to include the break statement but it didn't work well. 

    if((p[z]+p[k])==C)
    {
        fprintf(fout, "Case #%d: %d %d", i+1, z+1, k+1);
*break;*
    }


----------



## harshilsharma63 (Dec 22, 2013)

I was asking because if you were a beginner, you shouldn't jump straight to code jam samples.


----------



## The Conqueror (Dec 23, 2013)

harshilsharma63 said:


> I was asking because if you were a beginner, you shouldn't jump straight to code jam samples.



I understand that, but just tried to solve it since it looked easy. So what could be the workaround for multiple outputs?


----------

