Advertisement
jaskaran_1

DIRECTI.c

Dec 23rd, 2012
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.78 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3. #include<string.h>
  4.  
  5. #include<stdlib.h>
  6.  
  7. inline int next_int()
  8.  
  9. {int n=0;
  10.  
  11. char c=getchar();
  12.  
  13. while(!(c>='0'&&c<='9'))
  14.  
  15. c=getchar();
  16.  
  17. while(c>='0'&&c<='9')
  18.  
  19. {n=n*10+c-'0';
  20.  
  21. c=getchar();}
  22.  
  23. return n;
  24.  
  25. }
  26.  
  27. int main()
  28.  
  29. {int T,I,J,K,N;
  30.  
  31. char* string[40];
  32.  
  33. char* final[40];
  34. for(I=0;I<40;I++)
  35. final[I]="";
  36.  
  37. T=next_int();
  38.  
  39. for(I=1;I<=T;I++)
  40.  
  41. {N=next_int();
  42.  
  43. for(J=0;J<N;J++)
  44.  
  45. {gets(string[J]);
  46. strcpy(final[N-1-J],string[J]);
  47. }
  48.  
  49. strncpy(final[0],"Begin",5);//for the first one
  50.  
  51. for(J=N-1,K=1;J>=1,K<N;J--,K++)
  52.  
  53. {char *p=string[J];
  54.  
  55.  char *q=final[K];
  56.  
  57. if(*p=='R')
  58.  
  59. strncpy(q,"Left",4);
  60.  
  61. else if(*p=='L')
  62.  
  63. strncpy(q,"Right",5);
  64.  
  65. }
  66.  
  67. for(J=0;J<N;J++)
  68.  
  69. {printf("%s\n",final[J]);}
  70.  
  71. printf("\n");
  72.  
  73. }
  74.  
  75. return 0;
  76.  
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement