#33156: RE:WA(line:7)我不懂是哪裡出錯了,請好心人幫我看一下。


bagbwj63@gmail.com (Jay Wu)

學校 : 不指定學校
編號 : 211129
來源 : [140.138.241.165]
最後登入時間 :
2023-05-25 11:15:53
c082. 00118 - Mutant Flatworld Expolrers -- UVa118 | From: [60.251.127.173] | 發表日期 : 2022-12-06 20:19

我的output是 39 0 W lost,正確的是39 0 W,我不知道是哪個input導致是這樣。

#include <iostream>
#include<string>
using namespace std;

int main()
{
    int x, y;
    int px, py;
    cin >> x >> y;
    while (cin >> px >> py) {
        string f;
        string p;
        cin >> p;
        int n = 0;
            do {
                int i = 0;
                cin >> f;
                i++;
            } while (cin.get() == '\032');
        for (int j = 0; j < f.length(); j++) {
            if (f[j] == 'L' || f[j] == 'R') {
                if (p == "N") {
                    if (f[j] == 'R') {
                        p = "E";
                    }
                    else if (f[j] == 'L') {
                        p = "W";
                    }
                }
                else if (p == "E") {
                    if (f[j] == 'R') {
                        p = "S";
                    }
                    else if (f[j] == 'L') {
                        p = "N";
                    }
                }
                else if (p == "S") {
                    if (f[j] == 'R') {
                        p = "W";
                    }
                    else if (f[j] == 'L') {
                        p = "E";
                    }
                }
                else if (p == "W") {
                    if (f[j] == 'R') {
                        p = "N";
                    }
                    else if (f[j] == 'L') {
                        p = "S";
                    }
                }
            }
            else if (f[j] == 'F') {
                if (p == "E" || p == "W") {
                    if (p == "E") {
                        px = px + 1;
                    }
                    else {
                        px = px - 1;
                    }
                }
                else if (p == "N" || p == "S") {
                    if (p == "N") {
                        py = py + 1;
                    }
                    else {
                        py = py - 1;
                    }
                }
            }
        }
        if (px > x || py > y || px < 0 || py < 0) {
            if (px > x) {
                cout << x << " " << py << " " << p << " " << "LOST" << endl;
            }
            else if (py > y) {
                cout << px << " " << y << " " << p << " " << "LOST" << endl;
            }
            else if (px < 0) {
                cout << "0" << " " << py << " " << p << " " << "LOST" << endl;
            }
            else if (py < 0) {
                cout << px << " " << "0" << " " << p << " " << "LOST" << endl;
            }
        }
        else {
            cout << px << " " << py << " " << p << endl;
        }
    }
}

 

 
#33167: Re: RE:WA(line:7)我不懂是哪裡出錯了,請好心人幫我看一下。


wrr606@gmail.com (Function)

學校 : 國立金門大學
編號 : 133433
來源 : [1.174.43.134]
最後登入時間 :
2024-05-19 20:57:18
c082. 00118 - Mutant Flatworld Expolrers -- UVa118 | From: [1.172.146.243] | 發表日期 : 2022-12-07 21:11

我的output是 39 0 W lost,正確的是39 0 W,我不知道是哪個input導致是這樣。

#include
#include
using namespace std;

int main()
{
    int x, y;
    int px, py;
    cin >> x >> y;
    while (cin >> px >> py) {
        string f;
        string p;
        cin >> p;
        int n = 0;
            do {
                int i = 0;
                cin >> f;
                i++;
            } while (cin.get() == '\032');
        for (int j = 0; j < f.length(); j++) {
            if (f[j] == 'L' || f[j] == 'R') {
                if (p == "N") {
                    if (f[j] == 'R') {
                        p = "E";
                    }
                    else if (f[j] == 'L') {
                        p = "W";
                    }
                }
                else if (p == "E") {
                    if (f[j] == 'R') {
                        p = "S";
                    }
                    else if (f[j] == 'L') {
                        p = "N";
                    }
                }
                else if (p == "S") {
                    if (f[j] == 'R') {
                        p = "W";
                    }
                    else if (f[j] == 'L') {
                        p = "E";
                    }
                }
                else if (p == "W") {
                    if (f[j] == 'R') {
                        p = "N";
                    }
                    else if (f[j] == 'L') {
                        p = "S";
                    }
                }
            }
            else if (f[j] == 'F') {
                if (p == "E" || p == "W") {
                    if (p == "E") {
                        px = px + 1;
                    }
                    else {
                        px = px - 1;
                    }
                }
                else if (p == "N" || p == "S") {
                    if (p == "N") {
                        py = py + 1;
                    }
                    else {
                        py = py - 1;
                    }
                }
            }
        }
        if (px > x || py > y || px < 0 || py < 0) {
            if (px > x) {
                cout << x << " " << py << " " << p << " " << "LOST" << endl;
            }
            else if (py > y) {
                cout << px << " " << y << " " << p << " " << "LOST" << endl;
            }
            else if (px < 0) {
                cout << "0" << " " << py << " " << p << " " << "LOST" << endl;
            }
            else if (py < 0) {
                cout << px << " " << "0" << " " << p << " " << "LOST" << endl;
            }
        }
        else {
            cout << px << " " << py << " " << p << endl;
        }
    }
}

 


相同問題請見https://zerojudge.tw/ShowThread?postid=10954&reply=7487#10954

 
ZeroJudge Forum