fork(1) download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4. #include <string.h>
  5. #include <ctype.h>
  6.  
  7. int main(){
  8. int grid[8][8];
  9. int i,j,t,kase,x1,y1,x2,y2,length;
  10. char name[100];
  11. for(i=0;i<8;i++){
  12. for(j=0;j<8;j++){
  13. grid[i][j]=1;
  14. }
  15. }
  16. scanf("%d",&t);
  17.  
  18.  
  19. for(kase=1;kase<=t;kase++){
  20. scanf("%d %d %d %d %s",&x1,&y1,&x2,&y2,name);
  21.  
  22. length=0;
  23. length=strlen(name)-1;
  24.  
  25. for(i=0;i<=length;i=i+2){
  26.  
  27. if(name[i]=='U'){
  28. if(grid[x1][y1+1]==1){
  29.  
  30. y1++;
  31. }
  32. }
  33. else if(name[i]=='D'){
  34. if(grid[x1][y1-1]==1){
  35. y1--;
  36. }
  37. }
  38. else if(name[i]=='L'){
  39. if(grid[x1-1][y1]==1){
  40. x1--;
  41. }
  42. }
  43. else if(name[i]=='R'){
  44. if(grid[x1+1][y1]==1){
  45. x1++;
  46. }
  47. }
  48.  
  49. }
  50. for(j=1;j<=length;j=j+2){
  51. if(name[j]=='U'){
  52. if(grid[x2][y2+1]==1){
  53. y2++;
  54. }
  55. }
  56. else if(name[j]=='D'){
  57. if(grid[x2][y2-1]==1){
  58. y2--;
  59. }
  60. }
  61. else if(name[j]=='L'){
  62. if(grid[x2-1][y2]==1){
  63. x2--;
  64. }
  65. }
  66. else if(name[j]=='R'){
  67. if(grid[x2+1][y2]==1){
  68. x2++;
  69. }
  70. }
  71. }
  72.  
  73. if(x1==x2 || y1==y2){
  74. printf("COLLISION\n");
  75. }
  76. else {
  77. printf("SAFE\n");
  78. }
  79.  
  80.  
  81.  
  82. }
  83.  
  84. return 0;
  85.  
  86. }
  87.  
Success #stdin #stdout 0s 2160KB
stdin
4
0 0 1 0 LL
0 0 3 0 RLRL
7 7 6 7 RRU
0 0 5 5 LRLRL
stdout
COLLISION
COLLISION
COLLISION
SAFE