居敬行简 2020-05-11 17:05 采纳率: 0%
浏览 130

uva 227 - Puzzle标准用例的屏幕输出和其他AC代码一模一样,但oj反馈老是WA

代码如下

#include<iostream>
#include<fstream>
using namespace std;
//#define fin cin
int main()
{
    //ifstream fin;
    //fin.open("in.txt");
    char puzzle[10][10];
    char order;
    int x = 0, y = 0;
    int num_of_puzzles = 1;
    cin.getline(puzzle[0], 7);
    while (puzzle[0][0] != 'Z')
    {
        //输入第二至五行
        for (int i = 1; i < 5; i++)
        {
            cin.getline(puzzle[i], 7);
        }

        //for循环找出空格位置,储存为(x,y)
        for (int i = 0; i < 5; i++)
        {
            for (int j = 0; j < 5; j++)
            {
                if ((puzzle[i][j] == ' ')||(puzzle[i][j] == '\0'))
                {
                    x = i;
                    y = j;
                }
            }
        }
        //逐字符输入命令
        cin >> order;
        //声明状态变量
        int status = 1;
        //模拟法执行命令
        while ((order != '0')&&(status))
        {
            status = 1;
            switch (order)
            {
            case 'A':
                if (x == 0)
                {
                    status = 0;
                    break;
                }
                else
                {
                    puzzle[x][y] = puzzle[x - 1][y];
                    puzzle[x - 1][y] = ' ';
                    x--;
                }
                break;
            case 'B':
                if (x == 4)
                {
                    status = 0;
                    break;
                }
                else
                {
                    puzzle[x][y] = puzzle[x + 1][y];
                    puzzle[x + 1][y] = ' ';
                    x++;
                }
                break;
            case 'L':
                if (y == 0)
                {
                    status = 0;
                    break;
                }
                else
                {
                    puzzle[x][y] = puzzle[x][y - 1];
                    puzzle[x][y - 1] = ' ';
                    y--;
                }
                break;
            case 'R':
                if (y == 4)
                {
                    status = 0;
                    break;
                }
                else
                {
                    puzzle[x][y] = puzzle[x][y + 1];
                    puzzle[x][y + 1] = ' ';
                    y++;
                }
                break;
            default:
                cout << "process wrong!\n";
                break;
            }
            cin >> order;
        }
        while (order != '0')
        {
            cin >> order;
        }
        //for循环输出puzzle
        if (num_of_puzzles > 1)cout << endl;
        if (status)
        {
            cout << "Puzzle #" << num_of_puzzles << ":\n";
            for (int i = 0; i < 5; i++)
            {
                for (int g = 0; g < 4; g++)
                    cout << puzzle[i][g] <<" ";
                cout << puzzle[i][4] << endl;
            }
        }
        else
        {
            cout << "Puzzle #" << num_of_puzzles << ":\n";
            cout << "This puzzle has no final configuration.\n";
        }
        //输入第一行
        num_of_puzzles++;
        cin.get();
        cin.getline(puzzle[0], 7);
    }
    //fin.close();
    return 0;
}
  • 写回答

1条回答 默认 最新

  • zqbnqsdsmd 2020-05-13 01:31
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 react-diff-viewer组件,如何解决数据量过大卡顿问题
  • ¥20 遥感植被物候指数空间分布图制作
  • ¥15 安装了xlrd库但是import不了…
  • ¥20 Github上传代码没有contribution和activity记录
  • ¥20 SNETCracker
  • ¥15 数学建模大赛交通流量控制
  • ¥15 为什么我安装了open3d但是在调用的时候没有报错但是什么都没有发生呢
  • ¥50 paddleocr最下面一行似乎无法识别
  • ¥15 求某类社交网络数据集
  • ¥15 靶向捕获探针方法/参考文献