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

Hrant Nurijanyan [RAU] Runtime Error(access Violtion) HELP!! [4] // Problem 1370. Magician 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;
}
Morteza Balvardi Re: Runtime Error(access Violtion) HELP!! [1] // Problem 1370. Magician 13 Apr 2014 13:57
add ""cout<<flush;""
in diffrent places and see if it works(sometimes solves the error)
Andrew Sboev [USU] Re: Runtime Error(access Violtion) HELP!! // Problem 1370. Magician 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
Khujamurod Murtozakulov (Tashkent U of IT) Re: Runtime Error(access Violtion) HELP!! // Problem 1370. Magician 7 Nov 2018 19:52
1 ≤ M ≤ 32767. and you are trying to print a[j] which j >= m
ToadMonster Re: Runtime Error(access Violtion) HELP!! // Problem 1370. Magician 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.