Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. //
  2. // main.cpp
  3. // CCC
  4. //
  5. // Created by Vlad Russu on 22/03/2019.
  6. // Copyright © 2019 Vlad Russu. All rights reserved.
  7. //
  8.  
  9. #include <iostream>
  10. #include <fstream>
  11. #include <stdlib.h>
  12. #include <stdio.h>
  13.  
  14. FILE *f = fopen("level2_5.in", "r");
  15. FILE *g = fopen("level2_5a.out", "w");
  16.  
  17. int x,y;
  18. int wx, wy;
  19. int steps;
  20. int orientation;
  21.  
  22. int main(int argc, const char * argv[]) {
  23.  
  24. if(f == NULL){
  25. return -1;
  26. }
  27.  
  28. fscanf(f,"%d%d", &wx, &wy);
  29. fscanf(f,"%d%d", &x, &y);
  30.  
  31. char command;
  32. char s1[1];
  33.  
  34. fprintf(g, "%d %d\n", x, y);
  35.  
  36. while(fscanf(f,"%s", s1) == 1){
  37. fscanf(f, "%d", &steps);
  38. command = s1[0];
  39.  
  40. if(command == 'F'){
  41. switch(orientation){
  42. case 0:
  43. // x+=steps;
  44. for(int i=0;i<steps;i++){
  45. x++;
  46. fprintf(g, "%d %d\n", x, y);
  47. }
  48. break;
  49. case 1:
  50. // y+=steps;
  51. for(int i=0;i<steps;i++){
  52. y++;
  53. fprintf(g, "%d %d\n", x, y);
  54. }
  55. break;
  56. case 2:
  57. // x-=steps;
  58. for(int i=0;i<steps;i++){
  59. x--;
  60. fprintf(g, "%d %d\n", x, y);
  61. }
  62. break;
  63. case 3:
  64. // y-=steps;
  65. for(int i=0;i<steps;i++){
  66. y--;
  67. fprintf(g, "%d %d\n", x, y);
  68. }
  69. break;
  70. }
  71.  
  72. }
  73. else{
  74. orientation = (orientation + steps) % 4;
  75. }
  76. }
  77.  
  78. // fprintf(g, "%d %d\n", x, y);
  79. fclose(f);
  80. fclose(g);
  81.  
  82. return 0;
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement