Chef and Rainbow Array Solution Codechef RAINBOWA solution in C, C++, Java, Python and C#
CodeChef Problem Link Main Link- https://www.codechef.com/problems/RAINBOWA
Problem Name: Chef and Rainbow Array solution Codechef
Problem Number : CodeChef- Chef and Rainbow Array RGAME
Online Judge : CodeChef Online Judge Solution
Category: Beginner
Solution Language : C,C plus plus, java, python, c#(c sharp)
CodeChef Solution Chef and Rainbow Array Code in C / Codechef RAINBOWA solution in c language:
#include<stdio.h>
int main()
{
int t,i,arr[100],n,p;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
p=0;
for(i=0;i<n;i++)
{
scanf("%d",&arr[i]);
}
if(arr[n/2]==7)
{
for(i=0;i<n/2;i++)
{
if(arr[i]!=arr[n-1-i])
{
p=-1;
break;
}
}
}
else
p=-1;
if(p==-1)
printf("no\n");
else
printf("yes\n");
}
return 0;
}
CodeChef Solution Chef and Rainbow Array Code / CodeChef RAINBOWA solution in CPP:
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
int tc;
scanf("%d",&tc);
while(tc--)
{
int n;
scanf("%d",&n);
int a[n];
for(int i=0;i<n;i++)
scanf("%d",&a[i]);
int ind=0, c=1,rain=1;
int b[13];
for(int i=0;i<(n/2);i++)
{
if(a[i]!=a[n-1-i])
{
rain=0;
break;
}
if(a[i]!=c)
c++;
if(a[i]!=c || c>7)
{
rain=0;
break;
}
}
if(rain==0 || a[n/2]!=7)
printf("no\n");
else
printf("yes\n");
}
return 0;
}
CodeChef Solution Chef and Rainbow Array Code / CodeChef RAINBOWA solution in Perl:
use strict;
use warnings;
chomp(my $number_of_tests = <>);
my @results;
for my $i (1..$number_of_tests) {
chomp(my $number_of_elements = <>);
chomp(my @test_array = split (/ /, <>));
push @results, rainbow_array($number_of_elements, \@test_array);
}
sub rainbow_array{
my ($elements, $array_ref) = @_;
my @test_array = @{ $array_ref };
my $i = 0;
my $j = $elements - 1;
my $result = "yes";
while ($i < $elements / 2) {
if (($test_array[$i] == $test_array[$j])
&& ($test_array[int($elements / 2)] == 7)
) {
$i++;
$j--;
}
else {
$result = "no";
last;
}
}
return $result;
}
print "$_\n" for @results;
CodeChef Solution Chef and Rainbow Array Code / CodeChef RAINBOWA solution in Python:
for _ in range(int(raw_input())):
n = int(raw_input())
a = map(int,raw_input().split())
x=[0]*7
y=[0]*7
if set(a)^set(range(1,8))!=set([]):
print "no"
continue
z=1
f=False
for i in range((n+1)//2):
if a[i]<z:
print a[i],z
f=True
break
z=a[i]
x[a[i]-1]+=1
if f:
print "no"
continue
z=7
for i in range(n//2,n):
if a[i]>z:
f=True
break
y[a[i]-1]+=1
if f or x!= y or 0 in x:
print "no"
else:
print "yes"
CodeChef Solution Chef and Rainbow Array Problem Code: RAINBOWA Code / CodeChef RAINBOWA solution in C# (C Sharp):
using System;
namespace nishu_01
{
public class RainBow_Array
{
public static void Main(String[] args)
{
bool var = true;
int t = int.Parse (Console.ReadLine ());
for (int i = 0; i < t; i++)
{
int k = 0, count = 0, j = 0;
int n = int.Parse (Console.ReadLine ());
string[] str = new string[n];
str =Console.ReadLine ().Split ();
int[] strtoint = new int[str.Length];
//Console.WriteLine (strtoint.Length);
for(j=0;j<strtoint.Length;j++)
{
strtoint [j] = int.Parse (str [j]);
}
if(strtoint[strtoint.Length/2]==7)
{
for(k=0;k<(strtoint.Length/2) && 7==strtoint[strtoint.Length/2];k++)
{
if (strtoint [0] == 0)
{
Console.WriteLine ("no");
var = false;
break;
}
else if ((strtoint [k] == strtoint [k+1]) || (strtoint [k] ==strtoint [k+1]-1 ))
continue;
else
{
Console.WriteLine ("no");
var =false;
break;
}
}
if (var == true && k == (strtoint.Length / 2))
{
for (k = ((n % 2 == 0) ? (strtoint.Length / 2) : (strtoint.Length / 2) + 1); k < strtoint.Length; k++)
{
count = count + 1;
if (strtoint [k] == strtoint [(strtoint.Length / 2) - count])
{
if (strtoint [k] == strtoint [(strtoint.Length / 2) - count] && k == strtoint.Length - 1)
Console.WriteLine ("yes");
}
//Console.WriteLine ("yes");
else
{
Console.WriteLine ("no");
break;
}
}
}
}
else
Console.WriteLine("no");
}
}
}
}
Demonstration:
Just implement this in coding. Since having any problem just put a comment below. Thanks
Tags: CodeChef Online Judge Solution, CodeChef OJ Solution list, CodeChef Problems Solution, CodeChef solver, Codechef all problem solution list, Codechef Chef and Rainbow Array code in C, CodeChef RAINBOWA code in C++, CodeChef Chef and Rainbow Array solution in C, Codechef solution, CodeChef RAINBOWA solution in C,CodeChef RAINBOWA solution in C++-CPP,CodeChef RAINBOWA solution in C# (C sharp),CodeChef RAINBOWA solution in Java,CodeChef RAINBOWA solution in Python,
No comments:
Post a Comment