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

×

wrong answer but right output ? Rainbow problem

#include<stdio.h>
int func(int [],int);
int n;
int main()
{
 int cas,n,a[100],yes[100],i,j;
 scanf("%d",&cas);
 if(cas<1||cas>100)
 goto x;
 for(i=0;i<cas;i+=1)
 {
  scanf("%d",&n);

  for(j=0;j<n;j++)
  {
   scanf("%d",&a[j]);


  }
  yes[i]=func(a,n-1);

 }
 int g;
 for(g=0;g<cas;g++)
  {
    if(yes[g]==1)
       printf("yes\n");
    else
    if(yes[g]==0)
       printf("no\n");
  }
  x:
 return 0;
}

int func(int a[],int n)
{
 int i,j;
 for(i=0,j=n;i<j;i++,j--)
 {
  if(a[i]!=a[j])
  return 0;
  else if(a[i+1]-a[i]>1)
  return 0;
  else if(a[i]<0)
  return 0;
  else if(a[i+1]=a[i]<0)
  return 0;
  else if(a[1]<1||a[i]>7)
  return 0;
 }
 return 1;
}

asked 02 Sep '17, 12:44

lord_axis's gravatar image

0★lord_axis
1
accept rate: 0%

edited 02 Sep '17, 13:47

vijju123's gravatar image

5★vijju123 ♦
12.1k1319


else if(a[i+1]=a[i]<0)

This seems wrong.

Also, where are you checking that the array has only elements in range [1,7]? If it ahs 8,9, or 10 then array isnt a rainbow array.

link

answered 02 Sep '17, 14:11

vijju123's gravatar image

5★vijju123 ♦
12.1k1319
accept rate: 18%

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:

×25

question asked: 02 Sep '17, 12:44

question was seen: 148 times

last updated: 02 Sep '17, 14:11