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

×

boken telephone!

# include<stdlib.h>

using namespace std;

int main() { int n; string a; int count1; 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; for(int i=0;i<n;i++) { int k=0; if(a[i]!=a[i]) {

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 1★ankit777
4919
accept rate: 12% 19.8k350498541

 0 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. answered 14 Apr '15, 12:23 893●2●11●35 accept rate: 10%
 toggle preview community wiki:
Preview

### Follow this question

By Email:

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

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• 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