gpt4 book ai didi

java - 将 Java 程序转换为 C++

转载 作者:行者123 更新时间:2023-11-28 03:24:57 25 4
gpt4 key购买 nike

<分区>

我已将此代码从 java 转换为 C++ 但我无法转换 boolean(变量)及其相关代码。请帮助并告诉我是否可以使用任何 header 。

boolean[][] bombs = new boolean[M+2][N+2];
for (int i = 1; i <= M; i++){
for (int j = 1; j <= N; j++){
bombs[i][j] = (Math.random() < p);
}
}
for (int i = 1; i <= M; i++) {
for (int j = 1; j <= N; j++){
if (bombs[i][j]) cout<<"* ";
else cout<<". ";
}
cout<<endl;
}
int[][] sol = new int[M+2][N+2];
for (int i = 1; i <= M; i++)
for (int j = 1; j <= N; j++)
for (int ii = i - 1; ii <= i + 1; ii++)
for (int jj = j - 1; jj <= j + 1; jj++)
if (bombs[ii][jj]) sol[i][j]++;

cout<<endl;

for (int i = 1; i <= M; i++) {
for (int j = 1; j <= N; j++)
if (bombs[i][j]) cout<<"* ";
else cout<<sol[i][j] + " ";
cout<<endl;
}

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