You are not logged in. Please login at www.codechef.com to post your questions!

×

why this is run time error pls tell!this was not exccepted!

boken telephone!

include<iostream>

include<stdio.h>

include<stdlib.h>

using namespace std;

int main() { int n; string a[6]; int count1[6]; cin>>n;

if(n<6)

{for(int i=0;i<n;i++)

{

cin>>count1[i];

if(count1[i]>=2 && count1[i]<=1000)

 {
   cin>>(a[i]);
  if(a[i].size()!=count1[i])
    break;

  }

} } int result[6]; for(int i=0;i<n;i++) { int k=0; if(a[i][0]!=a[i][1]) {

k++;

}


for(int j=1;j<count1[i]-1;j++)
    {
        if((a[i][j-1]!=a[i][j])||(a[i][j]!=a[i][j+1]))
             {
                  k++;               }
    }

if(a[i][count1[i]-2]!=a[i][count1[i]-1]) {

k++;
}

result[i]=k;

}

for(int i=0;i<n;i++) { cout<<result[i]<<endl;

} return 0; }

asked 13 Apr '15, 20:39

ankit777's gravatar image

1★ankit777
4919
accept rate: 12%

edited 14 Apr '15, 13:38

admin's gravatar image

0★admin ♦♦
19.8k350498541


The code is difficult to read this way.

You have created an array of size 6, but n can be upto 10^6 (1000000). So the code is accessing outside of array giving runtime error.

Also why have you used a string? I don't think the question asked for any string input.

link

answered 14 Apr '15, 12:23

dragonemperor's gravatar image

3★dragonemperor
89321135
accept rate: 10%

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×1,424

question asked: 13 Apr '15, 20:39

question was seen: 492 times

last updated: 14 Apr '15, 13:38