编号 题目 状态 分数 总时间 内存 代码 / 答案文件 提交者 提交时间
#3118 #1005. 兜圈子 Compile Error 0 0 ms 0 K C++ 17 / 1.2 K t330026054 2023-11-23 10:56:38
显示原始代码

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

int main() {
    int G[2] = { 1, 1 };
    int range[2];
    char move[1000];
    cout << "enter range" << endl;
    ;
    cin >> range[0] >> range[1];
    cout << "enter movement" << endl;
    cin.getline(move, 600, ' ');
    int guide = 0;
    cout << strlen(move) << endl;
    cout << range[0] << range[1] << endl;
    for (int counter = 0; counter < strlen(move); counter++) {
        cout << move[counter];
    }

    int trigger = 1;
    for (int counter = 0; counter < strlen(move); counter++) {
        if (move[counter] != ' ' && move[counter] != '\n') {
            if (move[counter] == 'U' && G[0] != 1) {
                G[0] = G[0] - 1;
                cout << " " << G[0] << " " << G[1] << endl;
            }

            if (move[counter] == 'D' && G[0] != range[0]) {
                G[0] = G[0] + 1;
                cout << " " << G[0] << " " << G[1] << endl;
            }

            if (move[counter] == 'L' && G[1] != 1) {
                G[1] = G[1] - 1;
                cout << " " << G[0] << " " << G[1] << endl;
            }

            if (move[counter] == 'R' && G[1] != range[1]) {
                G[1] = G[1] + 1;
                cout << " " << G[0] << " " << G[1] << endl;
            }
        }
    }

    if (G[0] == 1 && G[1] == 1) {
        cout << -1;
    } else {
        cout << G[0] << " " << G[1];
    }
}

编译信息

/sandbox/1/a.cpp: In function 'int main()':
/sandbox/1/a.cpp:16:10: error: 'strlen' was not declared in this scope
   16 |  cout << strlen(move) << endl;
      |          ^~~~~~
/sandbox/1/a.cpp:4:1: note: 'strlen' is defined in header '<cstring>'; did you forget to '#include <cstring>'?
    3 | #include <iostream>
  +++ |+#include <cstring>
    4 | using namespace std;