提交后与自己编译的不一样是怎么回事啊。。。
查看原帖
提交后与自己编译的不一样是怎么回事啊。。。
852826
xiaoni0v0楼主2023/8/23 15:17

求大神看看这个代码出现了什么问题?自己编译没问题,洛谷IDE也没问题,但交上去就WA和RE啊。。。

#include <bits/stdc++.h>
using namespace std;

int res = 0,
    direc[2] = {0, 0}, // 0 上 1 右 2 下 3 左
    posC[2], posF[2];
char arr[12][12];

void step(int &dir, int &row, int &col)
{
    switch (dir)
    {
    case 0:
        if (arr[row - 1][col] == '*')
            dir = (dir + 1) % 4;
        else
            row--;
        break;
    case 1:
        if (arr[row][col + 1] == '*')
            dir = (dir + 1) % 4;
        else
            col++;
        break;
    case 2:
        if (arr[row + 1][col] == '*')
            dir = (dir + 1) % 4;
        else
            row++;
        break;
    case 3:
        if (arr[row][col - 1] == '*')
            dir = (dir + 1) % 4;
        else
            col--;
        break;

    default:
        break;
    }
}

int main()
{
    memset(arr, '*', 12 * 12);
    // 输入
    for (int i = 1; i <= 10; i++)
    {
        for (int j = 1; j <= 10; j++)
        {
            arr[i][j] = getchar();
            if (arr[i][j] == 'C')
            {
                posC[0] = i, posC[1] = j;
            }
            else if (arr[i][j] == 'F')
            {
                posF[0] = i, posF[1] = j;
                arr[i][j] = '.';
            }
        }
        getchar();
    }

    // 处理
    while (true)
    {
        res++;

        step(direc[0], posC[0], posC[1]);
        step(direc[1], posF[0], posF[1]);

        if (posC[0] == posF[0] && posC[1] == posF[1])
            break;
        if (res > 1 << 20)
        {
            res = 0;
            break;
        }
    }

    // 输出
    cout << res << endl;

    return 0;
}
2023/8/23 15:17
加载中...