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

×

Why my code is wrong ?

link - https://www.codechef.com/status/TEMPLELA,soham213

#include <iostream>
using namespace std;

int main() {
     int flag1=1; int flag2 =1;int k=1;int t;
     cin>>t;
     while(t>0)
    {
    int c;
    cin>>c;
    int ar[c];
    for(int l=0;l<c;l++)
    {
        cin>>ar[l];
    }
    for(int i=0;i<c/2 + 1 ;i++)
    {
        if(ar[i]!=i+1)
        {
            flag1=0;
            break;
        }
    }
    for(int j=c-1;j>c/2 ; j--)
    {
        if(ar[j]!=k)
        {
             flag2=0;
             break;
        }
        k++;

    }
    if(ar[c/2 -1]!=ar[c/2 ]-1)
    flag1 =0;

    if(flag1 && flag2)
    cout<<"yes";
    else
    cout<<"no";
    --t;
    }
    return 0;
}

asked 16 Sep '17, 17:09

soham213's gravatar image

2★soham213
1
accept rate: 0%

edited 16 Sep '17, 17:40

vijju123's gravatar image

5★vijju123 ♦♦
15.4k12066


cout<<"yes"; else cout<<"no";

Print each answer on a new line? :p

link

answered 16 Sep '17, 17:42

vijju123's gravatar image

5★vijju123 ♦♦
15.4k12066
accept rate: 18%

1

This is one of the nightmares that newbies face.

(16 Sep '17, 18:03) trashmaster2★

You may have a look at simple solution approach here.

I have used the same idea, but much less code, only one for loop...

Hope it would be instructive...

Please Upvote if you find this helpful....

link

answered 16 Sep '17, 21:52

taran_1407's gravatar image

6★taran_1407
3.9k2892
accept rate: 22%

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:

×151
×70
×49

question asked: 16 Sep '17, 17:09

question was seen: 261 times

last updated: 16 Sep '17, 21:52