Friday, October 15, 2010

Code for Chatruka's Parallelogram



#include<iostream>



#include<string>



using namespace std;



int main()



{



    int i,j,k,l,count=0,mov=0,n=1,end=0;



    char A[200],B[100][100],C[100][100],T[10];



    gets(T);



   
count=0;mov=0;n=1;end=0;



    if(T[0]=='E')



    {



       
gets(A);



        while((2*n*n)<strlen(A))



        {



           
n++;



        }



        if(n%2==0)



        {



           
n++;



        }



       
k=0;l=1;end=0;



        for(i=0;i<n;i++)



        {



            for(j=0;j<n;j++)



            {



               
if(k<strlen(A))



                {



                   
B[i][j]=A[k];



                   
k=k+2;



               
}



               
else



               
{



                   
end=1;



                   
break;



               
}



            }



            if(end==1)



            {break;}



        }



        while(i<n)



        {



            while(j<n)



            {



               
B[i][j]='/';



               
j++;



            }



           
i++;



           
j=0;



        }



       
end=0;



        for(i=0;i<n;i++)



        {



            for(j=0;j<n;j++)



            {



               
if(l<strlen(A))



               
{



                   
C[i][j]=A[l];



                   
l=l+2;



               
}



               
else



               
{



                   
end=1;



                   
break;



               
}



            }



            if(end==1)



            {break;}



        }



        while(i<n)



        {



            while(j<n)



            {



               
C[i][j]='/';



               
j++;



            }



           
i++;



           
j=0;



        }



       
cout<<"OUTPUT IS"<<endl;



       
cout<<A<<endl;



       
i=n/2;j=n/2;mov=0;



       
cout<<B[i][j]<<C[i][j];



       
count++;



        while(count<n*n)



        {



           
mov++;



            for(k=0;k<mov;k++)



            {



               
if(count<n*n)



               
{



                   
j--;



                   
cout<<B[i][j]<<C[i][j];



                   
count++;



               
}



            }



            for(k=0;k<mov;k++)



            {



               
if(count<n*n)



               
{



                    i--;



                   
cout<<B[i][j]<<C[i][j];



                   
count++;



               
}



            }



           
mov++;



            for(k=0;k<mov;k++)



            {



               
if(count<n*n)



               
{



                
   j++;



                   
cout<<B[i][j]<<C[i][j];



                   
count++;



               
}



            }



            for(k=0;k<mov;k++)



            {



               
if(count<n*n)



               
{



                   
i++;



                   
cout<<B[i][j]<<C[i][j];



                   
count++;



               
}



            }



        }



       
cout<<endl;



    }



    else if(T[0]=='D')



    {



       
gets(A);



        while((2*n*n)<strlen(A))



        {



           
n++;



        }



        if(n%2==0)



        {



           
n++;



        }



       
i=n/2;j=n/2;mov=0;l=0;



       
B[i][j]=A[l];l++;



       
C[i][j]=A[1];l++;



        while(count<n*n)



        {



           
mov++;



            for(k=0;k<mov;k++)



            {



               
if(count<n*n)



               
{



                   
j--;



                   
B[i][j]=A[l];l++;



                   
C[i][j]=A[l];l++;



                   
count++;



               
}



            }



            for(k=0;k<mov;k++)



            {



               
if(count<n*n)



               
{



                   
i--;



                   
B[i][j]=A[l];l++;



                   
C[i][j]=A[l];l++;



                   
count++;



               
}



            }



           
mov++;



            for(k=0;k<mov;k++)



            {



               
if(count<n*n)



               
{



                   
j++;



                   
B[i][j]=A[l];l++;



                   
C[i][j]=A[l];l++;



                   
count++;



               
}



            }



            for(k=0;k<mov;k++)



            {



               
if(count<n*n)



               
{



                   
i++;



                   
B[i][j]=A[l];l++;



                   
C[i][j]=A[l];l++;



                   
count++;



               
}



            }



        }



       
cout<<"OUTPUT IS"<<endl;



        cout<<A<<endl;



        for(i=0;i<n;i++)



        {



            for(j=0;j<n;j++)



            {



               
if(B[i][j]!='/')



               
{cout<<B[i][j];}



               
if(C[i][j]!='/')



               
{cout<<C[i][j];}



            }



        }



       
cout<<endl;



    }    



    return 0;



}

1 comment: