Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.28 KB | None | 0 0
  1. //B8_b3_nhật kí hành trình
  2. #include<iostream>
  3. #include<fstream>
  4. using namespace std;
  5. ifstream fi("input.inp");
  6. ofstream fo("output.out");
  7.  
  8. struct toado{
  9.     int x;
  10.     int y;
  11. };
  12.  
  13. toado A,B,C;
  14. string s;
  15. int k;
  16.  
  17. void nhap(){
  18.     fi >> A.x >> A.y >> B.x >> B.y;
  19.     C = A;
  20.     fflush(stdin);
  21.     fi >> s;
  22. }
  23.  
  24. void chay(){
  25.     bool t = true;
  26.     for(int i = 0; i < s.length(); i++){
  27.         switch(s[i]){
  28.             case 'E' : C.x = C.x + 1; break;
  29.             case 'N' : C.y = C.y + 1; break;
  30.             case 'W' : C.x = C.x - 1; break;
  31.             case 'S' : C.y = C.y - 1; break;
  32.             default : if(t) { k = i; t = false;} break;
  33.         }
  34.     }
  35. }
  36.  
  37. void xuly(){
  38.     int x, y;
  39.     x = C.x - B.x;
  40.     y = C.y - B.y;
  41.     if(x == 0 || y == 0){
  42.         if(x == 0 && y == 0){
  43.             s[k] = 'N';
  44.             s[k+1] = 'S';
  45.             return;
  46.         }
  47.         if(x == 0){
  48.             if(y > 0){
  49.                 s[k] = 'S';
  50.                 s[k+1] = 'S';
  51.             }
  52.             else{
  53.                 s[k] = 'N';
  54.                 s[k+1] = 'N';
  55.             }
  56.         }
  57.         else{
  58.             if(x > 0){
  59.                 s[k] = 'W';
  60.                 s[k+1] = 'W';
  61.             }
  62.             else{
  63.                 s[k] = 'E';
  64.                 s[k+1] = 'E';
  65.             }
  66.         }
  67.     }
  68.     else{
  69.         if(x > 0){
  70.             s[k] = 'E';
  71.             if(y > 0) s[k+1] = 'N';
  72.             else s[k+1] = 'S';
  73.         }
  74.         else{
  75.             s[k+1] = 'W';
  76.             if(y > 0) s[k] = 'N';
  77.             else s[k] = 'S';
  78.         }
  79.     }
  80. }
  81.  
  82. int main(){
  83.     nhap();
  84.     chay();
  85.     xuly();
  86.     fo << s;
  87.     fi.close();
  88.     fo.close();
  89.     return 0;
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement