Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //B8_b3_nhật kí hành trình
- #include<iostream>
- #include<fstream>
- using namespace std;
- ifstream fi("input.inp");
- ofstream fo("output.out");
- struct toado{
- int x;
- int y;
- };
- toado A,B,C;
- string s;
- int k;
- void nhap(){
- fi >> A.x >> A.y >> B.x >> B.y;
- C = A;
- fflush(stdin);
- fi >> s;
- }
- void chay(){
- bool t = true;
- for(int i = 0; i < s.length(); i++){
- switch(s[i]){
- case 'E' : C.x = C.x + 1; break;
- case 'N' : C.y = C.y + 1; break;
- case 'W' : C.x = C.x - 1; break;
- case 'S' : C.y = C.y - 1; break;
- default : if(t) { k = i; t = false;} break;
- }
- }
- }
- void xuly(){
- int x, y;
- x = C.x - B.x;
- y = C.y - B.y;
- if(x == 0 || y == 0){
- if(x == 0 && y == 0){
- s[k] = 'N';
- s[k+1] = 'S';
- return;
- }
- if(x == 0){
- if(y > 0){
- s[k] = 'S';
- s[k+1] = 'S';
- }
- else{
- s[k] = 'N';
- s[k+1] = 'N';
- }
- }
- else{
- if(x > 0){
- s[k] = 'W';
- s[k+1] = 'W';
- }
- else{
- s[k] = 'E';
- s[k+1] = 'E';
- }
- }
- }
- else{
- if(x > 0){
- s[k] = 'E';
- if(y > 0) s[k+1] = 'N';
- else s[k+1] = 'S';
- }
- else{
- s[k+1] = 'W';
- if(y > 0) s[k] = 'N';
- else s[k] = 'S';
- }
- }
- }
- int main(){
- nhap();
- chay();
- xuly();
- fo << s;
- fi.close();
- fo.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement