Stuck at a codejam question.

Hi fellas, actually I was practising some google code jam problems. And I got stuck at this question. I thought that I have pretty much figured it out. But when I ran the program, it crashed at the input provided.
The question is:[url] https://code.google.com/codejam/contest/351101/dashboard#s=p0 [/url]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
 #include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

using namespace std;
int a[100];
int g[200];
int seperate(char[]);
void ini();
int main(){
 /*freopen("input.txt", "rt", stdin);
        freopen("output.txt", "wt", stdout);*/
char buf[34];
int N,credit,flag;
ini();
char eq[200],ans[20];
cin>>N;
int l;
cin.getline(buf,34);
for(int c=0; c<N; c++)
{
   cin>>credit;

   cin.getline(eq,200);
    flag=0;
   l=seperate(eq);

   for(int i=0; i<l,!flag; i++){
    for(int ff=0; ff<l,!flag; ff++)
    {

        if(ff!=i){
            if((g[i]+g[ff])==credit){
                cout<<i+1<<" "<<ff+1<<endl;
                flag=1;
            }
        }
    }
   }

}
return 0;
}
void ini(){
for(int i=0; i<200; i++)
    g[i]=0;

}
int seperate(char str[]){
int d=0;
    for(int i=0; str[i]!='\0'; i++){
        if(str[i]!=' '){
            a[d]=str[i]-48;
            d++;}else if(str[i]==' '){
            a[d]=-1;
            ++d;
            }
    }
    int e=0,t=0,h;

    for(int f=d-1; f>-1; f--){
        for( h=f; a[f]==-1; h--){

            g[e]+=a[h]*pow(10,t);
            t++;
        }
        f=h;
        e++;
        t=0;
    }

    return e;
}



Thanks in advance.
Last edited on
i would do this way:
200 :money
7 : items
150 24 79 50 88 345 3 :prices


store the prices in a array
using a nested loop i calculate the sum, when sum==200; result is outer index + inner index
Actually, after reading the question a little bit more carefully- I realised that the user is also going to provide the number of items.
:/

Probably going to write the code again. But still I was not able to understand, why this code is crashing.
Topic archived. No new replies allowed.