C/C++
Помогите с задачей на c++
Даны два числа: n и m . Создайте двумерный массив размером n×m и заполните его символами 1 и 0 в шахматном порядке. В левом верхнем углу должна стоять единица. (сириус)
#include
using namespace std;
int main()
{
int k, l, m, n; cout > n >> m;
int **A = new int *[n];
for (k = 0; k < n; ++k)
{
A[k] = new int [m];
for (l = 0; l < m; ++l)
{ A[k][l] = ((k + l) & 1 ? 0 : 1); cout
#include
#include
#include
#include
using namespace std;
class MatrixChar {
public:
explicit MatrixChar(const size_t rows, const size_t cols) noexcept
: rows(rows), cols(cols) {
matrix.resize(rows);
for (auto& row : matrix) {
row.resize(cols);
for (auto& pos :row) {
pos = '0';
}
}
}
void chess_fill() noexcept {
for (size_t i = 0; i < rows; ++i) {
size_t j = i & 1 ? 1 : 0;
while (j < cols) {
matrix[i][j] = '1';
j += 2;
}
}
}
void show()const noexcept {
stringstream ss;
for (auto& row : matrix) {
for (auto& pos : row) {
ss m;
MatrixChar matrix(n, m);
matrix.chess_fill();
matrix.show();
}
#include
#include
using namespace std;
int main()
{
int n, m;
cin >> n >> m;
vector a(n, vector(m));
for(int i = 0; i < n; ++i)
for(int j = 0; j < m; ++j)
a[i][j] = (i + j) % 2 == 0;
for(int i = 0; i < n; ++i)
{
for(int j = 0; j < m; ++j)
cout
Похожие вопросы
- ПОМОГИТЕ С ЗАДАЧЕЙ НА C++
- Помогите решить задачу по C++!
- Помогите решить задачу на C++.
- Помогите с задачей по C++
- Помогите решить задачу на C++
- Помогите решить задачу на c++
- Помогите решить задачу на C++
- Помогите с задачей по C++
- Помогите с задачей в C++ пожалуйста. Какое условие правильно написать в Z чтобы выводилось сообщение "error!" ?
- Помогите решить задачу на C++