mardi 2 avril 2019

Runtime error when submitting to Kattis c++

I solved this problem (https://open.kattis.com/problems/apaxiaaans) in c++ and it worked fine using the sample inputs. However, when I submit the code to Kattis, it's saying that I have a runtime error.

Right now I am not sure what to do since, my code works fine using the sample inputs. Below is my code.

#include <iostream>
#include <fstream>
#include <string>
using std::cout;
using std::cin;

int main(){
    std::ifstream input_file;
    std::string file_path, user_input;
    cin >> file_path;
    input_file.open(file_path);

    if (!input_file) {
        cout << "Unable to open file";
        exit(1);
    } else {
        input_file >> user_input;
        input_file.close();

    };
    std::string answer;
    answer = user_input[0];
    for(int i=1; i < user_input.size(); i++){
        if(user_input[i] != user_input[i-1]){
            answer += user_input[i];
        }
    }
    cout << answer << std::endl;
    return 0;
}

Aucun commentaire:

Enregistrer un commentaire