ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1054. Tower of Hanoi

what case is not obeyed in my code??
Posted by Ravi Maggon 21 Aug 2010 19:08
Tried all test cases i know but it gives wrong answer for test#1.
Can anyone please tell me what case is failing in my code?

#include<stdio.h>
int count=0,ni;
int seq[31][31];
int a=-1,b=-1,c=-1,move=-1,movea=-1,moveb=-1,movec=-1,flag=0,go=0;
void tower(int n,char beg,char aux,char end)
{
     if(n==1)
     {
            int begin,ends,k,m;
            begin=(int)(beg-48)-1;
            ends=(int)(end-48)-1;
            count++;
            for(k=ni-1;k>0;k--)
                seq[ends][k]=seq[ends][k-1];
            seq[ends][0]=seq[begin][0];
            for(k=0;k<ni-1;k++)
                        seq[begin][k]=seq[begin][k+1];
            seq[begin][ni-1]=0;
            /*for(k=0;k<3;k++)
            {
                            for(m=0;m<ni;m++)
                                             printf("%d",seq[k][m]);
                            printf("\n");
                            }
                            printf("\n");
            */for(k=0;k<ni;k++)
            {
                    if(seq[a][k]==1)
                    {
                          movea=1;
                          break;
                    }
            }
            for(k=0;k<ni;k++)
            {
                    if(seq[b][k]==2)
                    {
                          moveb=1;
                          break;
                    }
            }
            for(k=0;k<ni;k++)
            {
                    if(seq[c][k]==3)
                    {
                          movec=1;
                          break;
                    }
            }
            if(movea==1&&moveb==1&&movec==1&&flag==0)
            {
                          flag=1;
                          move=count;
            }
            movea=-1;
            moveb=-1;
            movec=-1;
            return;
     }
     else
     {
            tower(n-1,beg,end,aux);
            tower(1,beg,aux,end);
            tower(n-1,aux,beg,end);
     }
}
void assign()
{
     int k,j;
     for(k=1;k<3;k++)
     {
             for(j=0;j<ni;j++)
                     seq[k][j]=0;
     }
             for(j=0;j<ni;j++)
                     seq[0][j]=(j+1);
}
int main()
{
    scanf("%d",&ni);
    assign();
    scanf("%d %d %d",&a,&b,&c);
    if(a==1)
            a--;
    else
    if(a==3)
            a=1;
    if(b==1)
            b--;
    else
    if(b==3)
            b=1;
    if(c==1)
            c--;
    else
    if(c==3)
            c=1;
    tower(ni,'1','2','3');
    printf("%d",move);
    return 0;
}