123_cjc @ 2024-07-28 16:58:58
rt
#include<iostream>
using namespace std;
int s[100][100], n;
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> s[i][j];
if (s[i][j] == 0) s[i][j] = 2;
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (s[i][j] == 2) s[i][j] = 0;
else break;
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (s[j][i] == 2) s[j][i] = 0;
else break;
}
}
for (int i = n - 1; i >= 0; i--) {
for (int j = n - 1; j >= 0; j--) {
if (s[i][j] == 2) s[i][j] = 0;
else break;
}
}
for (int i = n - 1; i >= 0; i--) {
for (int j = n - 1; j >= 0; j--) {
if (s[j][i] == 2) s[j][i] = 0;
else break;
}
}
for (int i = 0; i < n; i++) {
if (s[i][i] == 2) s[i][i] = 0;
else break;
}
for (int i = n - 1; i >= 0; i--) {
if (s[i][i] == 2) s[i][i] = 0;
else break;
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cout << s[i][j] << " ";
}
cout << endl;
}
for (int i = 0; i < n; i++) {
if (s[i][i] == 2) s[i][i] = 0;
else break;
}
for (int i = n - 1; i >= 0; i--) {
if (s[i][i] == 2) s[i][i] = 0;
else break;
}
return 0;
}
by Disjoint_cat @ 2024-07-28 17:13:06
@123_cjc 你在写神马,你这代码没一点道理,随便找个围得很深的外面的点你不就寄了。建议去学学 floodfill。
by 123_cjc @ 2024-07-28 17:15:48
@Disjoint_cat 我复制错了
#include<iostream>
using namespace std;
int s[100][100],n;
int main() {
cin>>n;
for(int i=0; i<n; i++)
for(int j=0; j<n; j++) {
cin>>s[i][j];
if(s[i][j]==0)s[i][j]=2;
}
for(int i=0; i<n; i++)
for(int j=0; j<n; j++) {
if(s[i][j]==2)s[i][j]=0;
else break;
}
for(int i=0; i<n; i++)
for(int j=0; j<n; j++) {
if(s[j][i]==2)s[j][i]=0;
else break;
}
for(int i=n-1; i>=0; i--)
for(int j=n-1; j>=0; j--) {
if(s[i][j]==2)s[i][j]=0;
else break;
}
for(int i=n-1; i>=0; i--)
for(int j=n-1; j>=0; j--) {
if(s[j][i]==2)s[j][i]=0;
else break;
}
for(int i=0; i<n; i++) {
for(int j=0; j<n; j++)cout<<s[i][j]<<" ";
cout<<endl;
}
}
by 123_cjc @ 2024-07-28 17:18:00
已关
by Disjoint_cat @ 2024-07-28 17:21:07
@123_cjc 都说了是 floodfill,这代码全是错的(
by Linkaifan1227 @ 2024-08-06 19:05:54
不建议BM