junkayden's blog

By junkayden, 7 years ago, In English

My code is working with my Xcode and gnu(g++) compiler, but codeforces gnu g++14 compiler is keep showing me runtime error. I can't understand why.

exit code is: "-1073781419"

This is my code-

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {

    int n, need, notin;
    vector<string> snacks,ans;
    cin >> n;
    for(int i = 1; i <= n; i++) {
        string size;
        cin >> size;
        snacks.push_back(size);
    }
    
    need = n;
    for(int i = 0; i < snacks.size();  i++) {
        if(snacks[i] == to_string(need)) {
            if(notin != 0) {
                for(int j = notin; j != 0; j--) {
                    snacks[i] += " " + snacks[i-j];
                    notin--;
                    need--;
                }
            }
            ans.push_back(snacks[i]);
            need--;
        } else {
            notin++;
            ans.push_back("0");
        }
    }
    for(int i = 0; i < ans.size(); i++) {
        if(ans[i] == "0") {
            cout << endl;
        } else {
            cout << ans[i] << endl;
        }
    }
    return 0;

}

Full text and comments »

  • Vote: I like it
  • -18
  • Vote: I do not like it