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

×

[Beginner] [Rainbow] Wrong Solution but working in terminal

Link to the question : https://www.codechef.com/problems/RAINBOWA Can anyone tell me why my code is being accepted. Here's my code in C :

    #include<stdio.h>

    int main()
    {
      int t, ele, y=0, i, quo, rem, k;
      //printf("Enter number of times to run loops: ");
      scanf("%d",&t);
      int counter[t];
      while(y<t)
      {
          //printf("Enter the number of elements: ");
          scanf("%d",&ele);
          int a[ele];
          counter[y] = 0;

          for(i=0;i<ele;i++)
          {
            scanf("%d",&a[i]);
          }

          quo = ele / 2;
          rem = ele % 2;
          k = quo + rem;

          for(i=0;i<k-1;i++)
          {
            if (a[i] != a[i+1] && a[i] + 1 != a[i+1])
            {
              counter[y]++;
              break;
            }

            if(a[i] != a[ele-1-i])
            {
              counter[y]++;
              break;
            }

          }
          y++;
      }
      for(i=0;i<t;i++)
      {
          if(counter[i] == 0){
            printf("yes\n");
          }
          else{
            printf("No\n");
          }
      }
      return 0;
    }

asked 25 Aug '17, 00:02

mihirsam's gravatar image

0★mihirsam
32
accept rate: 0%

edited 25 Aug '17, 00:04


Tiny mistake: you're printing "No" instead of "no".

One more mistake, you should verify that a[0] is 1 and a[k]is 7, because each number must appear non-zero number of times.

link

answered 25 Aug '17, 00:09

meooow's gravatar image

6★meooow ♦
6.6k717
accept rate: 49%

edited 25 Aug '17, 00:12

Thank you. It worked.

(25 Aug '17, 00:33) mihirsam0★
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,402
×360
×36
×25

question asked: 25 Aug '17, 00:02

question was seen: 150 times

last updated: 25 Aug '17, 00:33