codechef DIRECTI - "reversing directions" solution : http://ideone.com/Pwnt6i
#include<stdio.h>
#include <string.h>
int main()
{
char tem,a[60][60];
int t,n,i,j;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
scanf("%c",&tem);
for(i=0;i<n;i++)
gets(a[i]);
/*for(i=0;i<n;i++)
puts(a[i]);
*/printf("Begin");
if(a[n-1][0]=='R')
for(j=5;j<strlen(a[n-1]);j++)
printf("%c",a[n-1][j]);
else if(a[n-1][0]=='L')
for(j=4;j<strlen(a[n-1]);j++)
printf("%c",a[n-1][j]);
printf("\n");
for(i=(n-2);i>=0;i--)
{
if(a[i+1][0]=='R')
{
printf("Left");
if(a[i][0]=='L')
j=4;
else
j=5;
for(;j<strlen(a[i]);j++)
printf("%c",a[i][j]);
printf("\n");
}
else if(a[i+1][0]=='L')
{
printf("Right");
if(a[i][0]=='L')
j=4;
else
j=5;
for(;j<strlen(a[i]);j++)
printf("%c",a[i][j]);
printf("\n");
}
}
printf("\n");
}
scanf("%c%c",&tem,&tem);
return 0;
}
note: i was damn tired of gets(). later, i learned from stackoverflow that gets() function was officially deprecated. so i switched to c from c++, and tried my chance there, still no. so i glanced other AC codes, and mine was almost same with the above code, but still runtime error. since i dont know how to read whole line other than gets(), i just copy pasted at the end :(
No comments:
Post a Comment