2 条题解
-
0朱文博 (slz朱文博) LV 7 @ 2024-4-16 17:23:42
#include<bits/stdc++.h> using namespace std; const int INF=0x3f3f3f3f; const int N=1e9+10; int n,m,a[1005][1005],b[1005][1005],c[1005][1005]; int main(){ cin>>n>>m; for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ cin>>a[i][j]; c[i][j]=a[i][j]; if(a[i][j]==-1) a[i][j]=0; } } for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ b[i][j]=a[i][j]+a[i+1][j+1]+a[i+1][j-1]+a[i+1][j]+a[i][j+1]+a[i][j-1]+a[i-1][j+1]+a[i-1][j]+a[i-1][j-1]; } } for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ if(c[i][j]==-1) b[i][j]=-1; } } for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ if(b[i][j]==-1){ cout<<"*"<<" "; } else{ cout<<b[i][j]<<" "; } } cout<<endl; } return 0; }
-
02024-4-16 17:16:01@
#include<iostream> #include<stdio.h> using namespace std; int a[1001][1001]; int c[1001][1001]; int main() { int n,m; cin >> n >> m; for(int i = 1; i <= n; i++) { for(int j = 1; j <= m; j++) { cin >> a[i][j]; c[i][j] = a[i][j]; } } for(int i = 1; i <= n; i++) { for(int j = 1; j <= m; j++) { if(c[i][j] == -1) continue; if(c[i-1][j-1] != -1) a[i][j] += c[i-1][j-1]; if(c[i+1][j-1] != -1) a[i][j] += c[i+1][j-1]; if(c[i-1][j+1] != -1) a[i][j] += c[i-1][j+1]; if(c[i+1][j+1] != -1) a[i][j] += c[i+1][j+1]; if(c[i][j-1] != -1) a[i][j] += c[i][j-1]; if(c[i][j+1] != -1) a[i][j] += c[i][j+1]; if(c[i+1][j] != -1) a[i][j] += c[i+1][j]; if(c[i-1][j] != -1) a[i][j] += c[i-1][j]; } } for(int i = 1; i <= n; i++) { for(int j = 1; j <= m; j++) { if(a[i][j] == -1) cout << "* "; else cout << a[i][j] <<" "; } cout << endl; } return 0; }
- 1
信息
- ID
- 3106
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 3
- 标签
- 递交数
- 22
- 已通过
- 15
- 上传者