Why am I getting SIGABRT?

Hi I am new to codechef and this is the first problem I have tried.

It runs fine on my own computer but I get SIGABRT when trying to submit.
Running with valgrind and address sanitizer both don’t show any errors.
Is there something about submissions I could have missed?

My submission here.
https://www.codechef.com/viewsolution/29786631

You are getting SIGABRT because of the stoi function which you used in your code !!

Thanks,

I fixed my solution, but am now getting a wrong answer, even when using cin and cout as the FAQ states. I’m not sure why, because the sample works correctly on my own computer.

https://www.codechef.com/viewsolution/29874977

 if (!L_lifeforce < 1) { bars_cleared++; }

You need brackets here

 if (!(L_lifeforce < 1)) { bars_cleared++; }

or more concisely

if (L_lifeforce > 0) { bars_cleared++; }

Since you are new here I’ll just tell you a few things you probably don’t know.

std::cout << bars_cleared << std::endl;

You don’t need need to write std before everything, instead, you can use

using namespace std;

at the start of your code
Also, you don’t need to pass everything by reference, you can instead declare a global variable at the start of your code
Also when using if followed by only a single function
you can use

 if (L_lifeforce >0) 
    bars_cleared++; 

Corrected code with my tips

//https://www.codechef.com/viewsolution/29877973
//you can use the above link to see it in the question
#include <iostream>
using namespace std;
int N_barriers;
    int H_height;
    int Y1_crouch;
    int Y2_jump;
    int life;
    int bar_type;
    int bar_diff;
    int bars_cleared;
    int T_tests = 0;
void load_nth_test(){
    cin >> N_barriers;
    cin >> H_height;
    cin >> Y1_crouch;
    cin >> Y2_jump;
    cin >> life;
    bars_cleared = 0;
}
void try_pass(){
    cin >> bar_type;
    cin >> bar_diff;
    if(bar_type == 1){ // floating barrier, try to crouch
        if(H_height - Y1_crouch <= bar_diff)
            return;
         else 
            life--;
            return;
        

    } else { // grounded barrier, try to jump
        if(Y2_jump >= bar_diff)
            return;
         else 
            life--;
            return;
        
    }
}

void edward_program(){
    cin >> T_tests;
    for(int i = 0; i < T_tests; i++) {
        load_nth_test();
        for (int k = 0; k < (N_barriers); k++) {
            try_pass();
            if (life>0)  
              bars_cleared++; 
        }
        cout << bars_cleared << endl;
    }
}
int main(int argc, char *argv[]) {
    edward_program();
    return 0;
}

Corrected code without my tips

//https://www.codechef.com/viewsolution/29877535
//you can use the above link to see it in the question
#include <iostream>

void load_nth_test(int* n_bars, int* h_height, int* y1_crouch, int* y2_jump, int* l_lifeforce, int* bars_cleared){
    std::cin >> *n_bars;
    std::cin >> *h_height;
    std::cin >> *y1_crouch;
    std::cin >> *y2_jump;
    std::cin >> *l_lifeforce;
    *bars_cleared = 0;
}


void try_pass(int* life, int* height, int* crouch, int* jump, int* bar_diff, int* bar_type){
    std::cin >> *bar_type;
    std::cin >> *bar_diff;

    if(*bar_type == 1){ // floating barrier, try to crouch
        if(*height - *crouch <= *bar_diff){
            return;
        } else {
            (*life)--;
            return;
        }

    } else { // grounded barrier, try to jump
        if(*jump >= *bar_diff){
            return;
        } else {
            (*life)--;
            return;
        }
    }
}

void edward_program(){

    int N_barriers;
    int H_height;
    int Y1_crouch;
    int Y2_jump;
    int L_lifeforce;
    int X_barrierdiff;
    int t_barriertype;
    int bars_cleared;
    int T_tests = 0;

    std::cin >> T_tests;

    for(int i = 0; i < T_tests; i++) {
        load_nth_test(&N_barriers, &H_height, &Y1_crouch, &Y2_jump, &L_lifeforce, &bars_cleared);

        for (int k = 0; k < (N_barriers); k++) {
            try_pass(&L_lifeforce, &H_height, &Y1_crouch, &Y2_jump, &X_barrierdiff, &t_barriertype);
            if (!(L_lifeforce < 1)) { bars_cleared++; }
        }
        std::cout << bars_cleared << std::endl;
    }
}

int main(int argc, char *argv[]) {
    edward_program();
    return 0;
}

This was also my first question :grinning:

Wow I can’t believe it was something so simple! Thanks a bunch, I’ll take all of this into consideration.