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 1370. Magician

Runtime Error(access Violtion) HELP!!
Posted by Hrant Nurijanyan [RAU] 18 Feb 2014 23:27
#include <iostream>
#include <string>
using namespace std;
int main()
{
    string a[3000];
    int n;
    int m;
    cin >> n;
    cin >> m;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    int j = m;
    for (int i = 0; i < 10; i++)
    {
        cout << a[j];
        j++;
        if (j == n )
        {
            j = 0;
        }
    }
    cout << endl;
    return 0;
}
Re: Runtime Error(access Violtion) HELP!!
Posted by Morteza Balvardi 13 Apr 2014 13:57
add ""cout<<flush;""
in diffrent places and see if it works(sometimes solves the error)
Re: Runtime Error(access Violtion) HELP!!
Posted by Andrew Sboev [USU] 13 Apr 2014 14:07
string a[3000];

Hmm. It's really funny to use string array for containing int values.

Edited by author 13.04.2014 14:08
Re: Runtime Error(access Violtion) HELP!!
1 ≤ M ≤ 32767. and you are trying to print a[j] which j >= m
Re: Runtime Error(access Violtion) HELP!!
Posted by ToadMonster 8 Nov 2018 13:03
m can be above n;
m can be above a length.

To put big arrays on stack is a bad idea. a should be dynamic array or vector.