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. for(i=0;i<length;i=i+2){
  25.  
  26. if(name[i]=='U'){
  27. if(grid[x1][y1+1]==1){
  28.  
  29. y1++;
  30. }
  31. }
  32. else if(name[i]=='D'){
  33. if(grid[x1][y1-1]==1){
  34. y1--;
  35. }
  36. }
  37. else if(name[i]=='L'){
  38. if(grid[x1-1][y1]==1){
  39. x1--;
  40. }
  41. }
  42. else if(name[i]=='R'){
  43. if(grid[x1+1][y1]==1){
  44. x1++;
  45. }
  46. }
  47.  
  48. }
  49. for(j=1;j<length;j=j+2){
  50. if(name[j]=='U'){
  51. if(grid[x2][y2+1]==1){
  52. y2++;
  53. }
  54. }
  55. else if(name[j]=='D'){
  56. if(grid[x2][y2-1]==1){
  57. y2--;
  58. }
  59. }
  60. else if(name[j]=='L'){
  61. if(grid[x2-1][y2]==1){
  62. x2--;
  63. }
  64. }
  65. else if(name[j]=='R'){
  66. if(grid[x2+1][y2]==1){
  67. x2++;
  68. }
  69. }
  70. }
  71. if(x1==x2 && y1==y2){
  72. printf("Case %d: COLLISION\n",kase);
  73. }else {
  74. printf("Case %d: SAFE\n",kase);
  75. }
  76.  
  77.  
  78. }
  79.  
  80. return 0;
  81.  
  82. }
  83.  
Success #stdin #stdout 0s 2160KB
stdin
3 
0 0 3 0 RLRL 
7 7 6 7 RRU 
0 0 5 5 LRLRL
stdout
Case 1: COLLISION
Case 2: COLLISION
Case 3: SAFE