How to write a C Program Roboturtle in C Programming Language ?
Solution For C Program :
/*C Program Roboturtle.*/
#include<stdio.h>
#include<string.h>
int walk,n,i,x=0,y=0,way=1,die=0;
char WAY='E',a[10];
main()
{
scanf("%d",&n);
for(i=0; i<n; i++)
{
scanf(" %s %d",&a,&walk);
if(a[0]=='R' && a[1]=='T')
{
way++;
if(way>3)
{
way=0;
}
}
else if(a[0]=='L' && a[1]=='T')
{
way--;
if(way<0)
{
way=3;
}
}
else if(a[0]=='B' && a[1]=='W')
{
way-=2;
if(way==-1)
{
way=3;
}
else if(way==-2)
{
way=2;
}
}
if(way==0)
{
if(y+walk>=50000)
{
die=1;
}
y=y+walk;
WAY='N';
}
else if(way==1)
{
if(x+walk>=50000)
{
die=1;
}
x=x+walk;
WAY='E';
}
else if(way==2)
{
if(y-walk<=-50000)
{
die=1;
}
y=y-walk;
WAY='S';
}
else if(way==3)
{
if(x-walk<=-50000)
{
die=1;
}
x=x-walk;
WAY='W';
}
}
if(die==1)
{
printf("DEAD");
}
else
{
printf("%d %d \n%c",x,y,WAY);
}
}