我的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;
}
}
}
我的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