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 2100. Wedding Dinner

What does it mean?
Posted by nick nikuradze 31 May 2017 21:39
What does it mean? Runtime error (access violation)
This is my code on c++
#include <iostream>
using namespace std;
int n,ans;
string s;
int main()
{
    cin>>n;
    ans=n+2;
    for(int i=0; i<n; i++)
    {
        cin>>s;
        for(int j=0; j<s.size()-3; j++)
        {
            if(s[j]=='+' && s[j+1]=='o' && s[j+2]=='n' && s[j+3]=='e')
            {
                ans++;
                break;
            }
        }
    }
    if(ans==13) ans++;
    cout<<100*ans;
    return 0;
}

Edited by author 31.05.2017 21:40
Re: What does it mean?
Posted by Mahilewets 31 May 2017 23:00
for(int j=0; j<(int) s.size()-3; j++)


Edited by author 31.05.2017 23:05

Edited by author 31.05.2017 23:05
Re: What does it mean?
Posted by Mahilewets 31 May 2017 23:02
The problem is "s. size() -3".
The type of s. size()  is SIZE_T.  It is UNSIGNED.  So,  if s. length <=2,then SIZE_T overflows.  The result is a HUGE number.  And j goes out of range.
Re: What does it mean?
Posted by Mahilewets 31 May 2017 23:04
"Access violation" means that you are trying to access some memory you are NOT SUPPOSED to access.

Edited by author 31.05.2017 23:04