This is the problem I am working on! *NOTE - THIS IS NOT A COMPETITION IT IS JUST A PROBLEM SET.
So this is my code. The compiler i am using is GNU C++11 This code runs fine with all the test cases provided. I dont know what to do. Any help would be appreciated! :)
#include<iostream>
#include<conio.h>
#include<windows.h>
int test(long int n,long int number[])
{
int flag=0;
for(int i=0;i<n;i++)
{
if(number[i+1]==number[i]+1)
flag++;
}
if(flag==n-1)
return 1;
else
return 0;
}
void rot_gears(long int n,long int number[])
{
system("cls");
int t;
for(long z=0;z<n*n;z++)
{
for(long i=0;i<n;i++)
{
if(i%2==0)
{
if(number[i]==n-1)
{
number[i]=0;
}
else
number[i]++;
}
else if(i%2!=0)
{
if(number[i]==0)
number[i]=n-1;
else
number[i]--;
}
}
t=test(n,number);
if(t==1)
break;
// output(n,number);
//cout<<"\n\n";
}
if(t)
std::cout<<"YES";
else
std::cout<<"NO";
}
int main()
{
long int n,teeth,number[10000];
std::cin>>n;
std::cin>>teeth;
for(long int i=n-1;i>=0;i--)
{
number[i]=teeth%10;
teeth/=10;
}
// output(n,number);
rot_gears(n,number);
return 0;
}
Aucun commentaire:
Enregistrer un commentaire