ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1880. Psych Up's Eigenvalues

runtime error (access violation) visual c++
Posted by beslana 2 Oct 2019 14:54
#include <iostream>
#include <stack>

using namespace std;
int main()
{
    unsigned short n1, n2, n3;
    int a, n=0;
    stack<int> group1;
    cin >> n1;
    for (int i = 0; i <n1; i++) {
        scanf_s("%d", &a);  group1.push(a);
    }

    stack<int> group2;
    cin >> n2;
    for (int i = 0; i < n2; i++) {
        scanf_s("%d", &a);  group2.push(a);
    }

    stack<int> group3;
    cin >> n3;
    for (int i = 0; i < n3; i++) {
        scanf_s("%d", &a);  group3.push(a);
    }

    while (!group1.empty()) {
        if (group1.top() == group2.top()) {
            if (group1.top() == group3.top()) {
                n++;
                group1.pop();
                group2.pop();
                group3.pop();
                if ((group1.empty()) || group2.empty() || group3.empty()) break;
            }
            else if (group1.top() > group3.top()) {
                group1.pop();
                group2.pop();
                if (group1.empty() || group2.empty()) break;
            }
            else group3.pop();
        }
        if (group1.top() > group2.top())group1.pop();
        if (group1.empty()) break;
        if (group1.top() < group2.top())group2.pop();
        if (group2.empty()) break;
    }
    cout << n;

}

what's wrong?
Re: runtime error (access violation) visual c++
Posted by beslana 2 Oct 2019 17:44
after else group3.pop();
 if (group3.empty()) break;
accapte