Q:

UVA Online Judge: Non-reproducible Runtime Error

My code compiled(g++) without errors and ran without errors on my system(Macos) for sample input from the website, but is showing a Runtime Error in the online judge. Please help, I'm a new programmer. This is the problem statement.
My program returns correct results for the test input data.
They haven't given the exact reason for the runtime error.
The website has this information about runtime error:
Runtime Error (RE): Your program failed during the execution (segmentation fault, floating point exception...). The exact cause is not reported to the user to avoid hacking. Be sure that your program returns a 0 code to the shell.
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>

using namespace std;

int main(){

    string line;

     while(getline( cin,line) && line != "" ){

         istringstream split(line);

         string kt,jt;

         getline(split, kt, ' ');
         getline(split, jt);

         int k = stoi(kt);
         int j = stoi(jt); 

        vector<int> all_cycles;

        for(int i = k; i<= j; i++){

            vector<int> cycle ;

            int temp  = i;

            while(temp != 1){

                cycle.push_back(temp);

                if(temp %2 == 0) temp = temp /2;

                else temp = (temp*3) + 1;

            }
            all_cycles.push_back(cycle.size() + 1 );
            cycle.clear();

        }       

        cout << k << " " << j << " " << *max_element(all_cycles.begin(), all_cycles.end())  << "\n";
        all_cycles.clear();

    }

    return 0;
}

Code Update 1:
Replaced vectors with counters.
Fixed undefined behavior if j < k.
Submitted the updated code, still Run time error.
#include <iostream>
#include <string>
#include <sstream>

using namespace std;

int main(){

    string line;

     while(getline( cin,line) && line != "" ){

         istringstream split(line);

         string kt,jt;

         getline(split, kt, ' ');
         getline(split, jt);

         int k = stoi(kt);
         int j = stoi(jt); 

        if(k > j) {
            int t = k;
            k = j;
            j = t;
        }

        int max_cycle = 0;

        for(int i = k; i<= j; i++){

            int  cycle = 1 ;
            int temp  = i;

            while(temp != 1){

                cycle++;

                if(temp %2 == 0) temp = temp /2;

                else temp = (temp*3) + 1;

            }
            if(cycle > max_cycle) max_cycle = cycle;

        }       

        cout << k << " " << j << " " <<  max_cycle << "\n";

    }

    return 0;
}

Code Update 2:
I replaceed string parsing the input by using formatted input and solved the newline detection problem by copying the next character of input from the streambuffer to a variable and checked if it is a newline. 
This updated code seems to get rid of the Runtime Error and Now it is an output error.
Which I should be able to solve through formatting my output.
So it seems that stoi in my earlier code  might have been throwing an exception during runtime.Thank you @walnut for pointing that out.
#include <iostream>

using namespace std;

int main(){

    int k, j;
    int eofile = 0;

     while(cin >> k >> j && !eofile ){

        streambuf * pbuf = cin.rdbuf();
        char ch = pbuf->snextc();
        if(ch == '\n')  eofile = 1;

        if(k > j) {
            int t = k;
            k = j;
            j = t;
        }

        int max_cycle = 0;

        for(int i = k; i<= j; i++){

            int  cycle = 1 ;
            int temp  = i;

            while(temp != 1){

                cycle++;

                if(temp %2 == 0) temp = temp /2;

                else temp = (temp*3) + 1;
            }
            if(cycle > max_cycle) max_cycle = cycle;
        }       

        cout << k << " " << j << " " <<  max_cycle << "\n";
    }

    return 0;
}

If there is a better way to get formatted input and also detect newline, please tell me how to do it.

A:

Solved the problem :
Program run without any errors with runtime : 0.330s
The runtime error was solved when I replaced the stoi() function with input formatting.   
Finally there was an output error because I was flipping k and j to prevent undefined behavior when j < k, which I solved by formatting the output accordingly.
#include <iostream>
#include <string>
#include <sstream>

using namespace std;

int main(){

    string line;

     while(getline( cin,line) && line != "" ){

         istringstream split(line);
         int k,j;

        split >> k >> j; 

        int flip = 0;

        if(k > j) {
            flip = 1;
            int t = k;
            k = j;
            j = t;
        }

        int max_cycle = 0;

        for(int i = k; i<= j; i++){

            int  cycle = 1 ;
            int temp  = i;

            while(temp != 1){

                cycle++;

                if(temp %2 == 0) temp = temp /2;

                else temp = (temp*3) + 1;

            }
            if(cycle > max_cycle) max_cycle = cycle;

        }       

        if(!flip) cout << k << " " << j << " " <<  max_cycle << "\n";
        else cout << j << " " << k << " " <<  max_cycle << "\n";

    }
    return 0;
}

Thanks to everyone for all the help.

