gpt4 book ai didi

c++ - 像时尚一样在网格中格式化 C++ 中的输入

转载 作者:行者123 更新时间:2023-11-27 23:55:29 24 4
gpt4 key购买 nike

在二维数组数独程序上工作,我希望用户输入用空格分隔,而不是让每个输入逐行输入。这将使用户更容易看到他们正在输入什么想法?希望它是 9 个数字乘 9 行而不是逐行。当前代码:

int main()

{

int grid[N][N];

//Input

std::cout << "Enter a Sudoku puzzle:" << std::endl;
for (int i = 0; i < 9; i++)
for (int j = 0; j < 9; j++)
std::cin >> grid[i][j];


std::cout << "Sodoku Puzzle: \n";
printSodoku(grid);
std::cout << "\n Solution: \n";

if (SolveSudoku(grid) == true)
printSodoku(grid);
else
printf("No solution exists");
_getch();
return 0;
}

最佳答案

您当前的代码允许这样做,因为 cin 获取任何空格之前的内容,将其输出到您的代码中,然后等待另一个 cin 并输出下一个内容。因此,无需任何修改,您的程序应该能够做到这一点。

关于c++ - 像时尚一样在网格中格式化 C++ 中的输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42914863/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com