54 条题解
-
4
Galileonardo LV 7 @ 7 年前
直接覆盖上去玩了。
#include <iostream>
using namespace std;char a[105][105];
int b[105][105];
int n,m;
char temp;int main(){
cin>>n>>m;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
temp=getchar();
if((temp=='*')||(temp=='?')){
a[i][j]=temp;
}else{
a[i][j]=getchar();
}
}}
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
if(a[i][j]=='*'){
for(int x=i-1;x<=i+1;x++){
for(int y=j-1;y<=j+1;y++){
b[x][y]++;
}
}
}
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(a[i][j]=='*'){
cout<<'*';
}else{
cout<<b[i][j];
}
}
cout<<endl;
}
return 0;
} -
28 年前@
#include<iostream>
#include<string.h>
using namespace std;
char a[105][105];
int m,n,b[105][105];
int c[16]={0,1,0,-1,1,0,-1,0,1,1,1,-1,-1,1,-1,-1};
int main()
{
//freopen("b.in","r",stdin);
//freopen("b.out","w",stdout);
cin>>n>>m;
memset(b,0,sizeof(b));
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)cin>>a[i][j];
}
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
if(a[i][j]=='*')
{
for(int k=0;k<16;k+=2)if(i+c[k]>=0&&i+c[k]<n&&j+c[k+1]>=0&&j+c[k+1]<m)b[i+c[k]][j+c[k+1]]++;
}
}
}
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
if(a[i][j]=='?')a[i][j]='0'+b[i][j];
}
}
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)cout<<a[i][j];
cout<<endl;
}
return 0;
}
-
12 年前@
-
13 年前@
-
14 年前@
-
16 年前@
-
17 年前@
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
char a[105][105];
int b[105][105];
int main()
{
//freopen("game.in","r",stdin);
//freopen("game.out","w",stdout);
int n,m;
cin>>n>>m;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
{
cin>>a[i][j];
if(a[i][j]=='*')
{
b[i][j]=10;
b[i+1][j]++;
b[i][j+1]++;
b[i+1][j+1]++;
b[i+1][j-1]++;
b[i][j-1]++;
b[i-1][j-1]++;
b[i-1][j]++;
b[i-1][j+1]++;
}
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
if(b[i][j]<10)
cout<<b[i][j];
else
cout<<"*";
}
cout<<endl;
}
return 0;
} -
18 年前@
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
char s[1001][1001];
int main(){
int i,j,k,n,m;
scanf("%d%d\n",&n,&m);
for(i=1;i<=n;i++){
for(j=1;j<=m;j++)
scanf("%c",&s[i][j]);
if(i!=n)scanf("\n");
}
for(i=1;i<=n;i++){
for(j=1;j<=m;j++)
if(s[i][j]=='*')printf("*");
else{
int la=0;
if(s[i-1][j]=='*')la++;
if(s[i-1][j-1]=='*')la++;
if(s[i-1][j+1]=='*')la++;
if(s[i+1][j]=='*')la++;
if(s[i+1][j-1]=='*')la++;
if(s[i+1][j+1]=='*')la++;
if(s[i][j-1]=='*')la++;
if(s[i][j+1]=='*')la++;
printf("%d",la);
}
printf("\n");
}
return 0;
} -
18 年前@
-
18 年前@
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#define N 101
using namespace std;
char a[N][N];
int tot;
int n,m;
int search(int x,int y )
{
if(x-1>=1&&y-1>=1&&a[x-1][y-1]=='*')
tot++;
if(x+1<=n&&y+1<=m&&a[x+1][y+1]=='*')
tot++;
if(x-1>=1&&a[x-1][y]=='*')
tot++;
if(x-1>=1&&y+1<=m&&a[x-1][y+1]=='*')
tot++;
if(y-1>=1&&a[x][y-1]=='*')
tot++;
if(y+1<=m&&a[x][y+1]=='*')
tot++;
if(x+1<=n&&y-1>=1&&a[x+1][y-1]=='*')
tot++;
if(x+1<=n&&a[x+1][y]=='*')
tot++;
return tot;
}
int main()
{
cin>>n>>m;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
{
cin>>a[i][j];
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
if(a[i][j] == '?')
{
tot=0;
printf("%d",search(i,j));
}
if(a[i][j]=='*')
printf("*");
}
cout<<endl;
}
return 0;
} -
18 年前@
#include <bits/stdc++.h>
using namespace std;
char a[105][105];
int b[105][105];
bool c[105][105];
int main()
{
int i,j,k,l,n,m;
cin>>n>>m;
memset(a,1,sizeof(c));
for(i=1;i<=n;i++) {
for(j=1;j<=m;j++) {
cin>>a[i][j];
if(a[i][j]=='*') {
b[i][j]=-1000000;
if(b[i+1][j]!=-1000000) b[i+1][j]++;
if(b[i-1][j]!=-1000000) b[i-1][j]++;
if(b[i][j+1]!=-1000000) b[i][j+1]++;
if(b[i][j-1]!=-1000000) b[i][j-1]++;
if(b[i+1][j+1]!=-1000000) b[i+1][j+1]++;
if(b[i-1][j+1]!=-1000000) b[i-1][j+1]++;
if(b[i+1][j-1]!=-1000000) b[i+1][j-1]++;
if(b[i-1][j-1]!=-1000000) b[i-1][j-1]++;
}
}
}
for(i=1;i<=n;i++){
for(j=1;j<=m;j++){
if(b[i][j]!=-1000000) cout<<b[i][j];
else cout<<"*";
}
cout<<endl;
}
return 0;
}
测试数据 #0: Accepted, time = 15 ms, mem = 624 KiB, score = 10测试数据 #1: Accepted, time = 0 ms, mem = 624 KiB, score = 10
测试数据 #2: Accepted, time = 15 ms, mem = 620 KiB, score = 10
测试数据 #3: Accepted, time = 0 ms, mem = 628 KiB, score = 10
测试数据 #4: Accepted, time = 0 ms, mem = 624 KiB, score = 10
测试数据 #5: Accepted, time = 15 ms, mem = 624 KiB, score = 10
测试数据 #6: Accepted, time = 0 ms, mem = 624 KiB, score = 10
测试数据 #7: Accepted, time = 15 ms, mem = 624 KiB, score = 10
测试数据 #8: Accepted, time = 0 ms, mem = 624 KiB, score = 10
测试数据 #9: Accepted, time = 15 ms, mem = 624 KiB, score = 10
Accepted, time = 75 ms, mem = 628 KiB, score = 100
-
18 年前@
program ex2;
var i,j,l,t,m,n:integer;
s:array[1..102,1..102] of char;
a:array[1..102,1..102] of integer;
b:array[1..102,1..102] of boolean;
begin
readln(n,m);
for i:=1 to n+2 do
for j:=1 to m+2 do
begin
s[i,j]:='?';
a[i,j]:=0;
end;
for i:=2 to n+1 do
begin
for j:=2 to m+1 do
begin
read(s[i,j]);
if s[i,j]='?' then b[i,j]:=true
else b[i,j]:=false;
end;
readln;
end;
for i:=2 to n+1 do
for j:=2 to m+1 do
for l:=i-1 to i+1 do
for t:=j-1 to j+1 do
if s[l,t]='*' then a[i,j]:=a[i,j]+1;
for i:=2 to n+1 do
begin
for j:=2 to m+1 do
if b[i,j] then write(a[i,j])
else write('*');
writeln;
end;
end. -
18 年前@
#include <iostream>
using namespace std;
char a[107][107],b[107][107];
int x[10]={1,1,1,0,0,0,-1,-1,-1},y[10]={1,0,-1,1,0,-1,1,0,-1},cur;
int main()
{
int m,n;
cin>>n>>m;
for(int i=0;i<=n+2;i++)
for(int j=0;j<=m+2;j++)
a[i][j]='?';
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
cin>>a[i][j];
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
cur=0;
if(a[i][j]=='*') cout<<"*";
else
{
for(int k=0;k<=8;k++)
if(a[i+x[k]][j+y[k]]=='*')
cur++;
cout<<cur;
}
}
cout<<endl;
}
system ("pause");
return 0;
} -
18 年前@
var a:array[0..100,0..100]of char;
n,m,t,i,j:longint;
begin
readln(n,m);
for i:=1 to n do begin
for j:=1 to m do
read(a[i,j]);
readln;
end;
for i:=1 to n do begin
for j:=1 to m do begin
t:=0;
if a[i,j]='*' then write('*')
else begin
if a[i-1,j]='*' then inc(t);
if a[i-1,j-1]='*' then inc(t);
if a[i-1,j+1]='*' then inc(t);
if a[i,j-1]='*' then inc(t);
if a[i,j+1]='*' then inc(t);
if a[i+1,j]='*' then inc(t);
if a[i+1,j-1]='*' then inc(t);
if a[i+1,j+1]='*' then inc(t);
write(t);
end;
end;
writeln;
end;
end.
比赛现场打的,好傻啊。。。 -
19 年前@
记录信息
评测状态 Accepted
题目 P1975 扫雷游戏
递交时间 2015-12-20 16:50:50
代码语言 Pascal
评测机 VijosEx
消耗时间 308 ms
消耗内存 656 KiB
评测时间 2015-12-20 16:50:51评测结果
编译成功Free Pascal Compiler version 2.6.2 [2013/02/12] for i386
Copyright (c) 1993-2012 by Florian Klaempfl and others
Target OS: Win32 for i386
Compiling foo.pas
foo.pas(4,1) Note: Local variable "ip" not used
foo.pas(4,4) Note: Local variable "op" not used
Linking foo.exe
33 lines compiled, 0.1 sec , 28864 bytes code, 1628 bytes data
2 note(s) issued
测试数据 #0: Accepted, time = 46 ms, mem = 652 KiB, score = 10测试数据 #1: Accepted, time = 31 ms, mem = 652 KiB, score = 10
测试数据 #2: Accepted, time = 31 ms, mem = 652 KiB, score = 10
测试数据 #3: Accepted, time = 31 ms, mem = 652 KiB, score = 10
测试数据 #4: Accepted, time = 31 ms, mem = 652 KiB, score = 10
测试数据 #5: Accepted, time = 46 ms, mem = 652 KiB, score = 10
测试数据 #6: Accepted, time = 31 ms, mem = 652 KiB, score = 10
测试数据 #7: Accepted, time = 31 ms, mem = 652 KiB, score = 10
测试数据 #8: Accepted, time = 15 ms, mem = 656 KiB, score = 10
测试数据 #9: Accepted, time = 15 ms, mem = 652 KiB, score = 10
Accepted, time = 308 ms, mem = 656 KiB, score = 100
代码
var
l:array[1..200,1..200]of char;
i,j,k,m,n:longint;
ip,op:text;
beginreadln(m,n);
fillchar(l,sizeof(l),'0');
for i:=2 to m+1 do begin//这里从位置2,2开始读是为了避免下标越界报错
for j:=2 to n+1 do read(l[i,j]);
readln;//注意这里一定要写,不写会读错的
end;
for i:=2 to m+1 do begin
for j:=2 to n+1 do begin
if l[i,j]='*' then
write('*');//如果是雷直接输出
if l[i,j]='?' then begin
k:=0;
if l[i,j+1]='*' then inc(k);//if语句判断是否加一
if l[i,j-1]='*' then inc(k);//同上
if l[i+1,j]='*' then inc(k);//同上
if l[i-1,j]='*' then inc(k);//同上
if l[i+1,j+1]='*' then inc(k);//同上
if l[i+1,j-1]='*' then inc(k);//同上
if l[i-1,j+1]='*' then inc(k);//同上
if l[i-1,j-1]='*' then inc(k);//同上
write(k);
end;
end;
writeln;//这边不加的话就变成一行了
end;end.
-
09 个月前@
-
07 年前@
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
int n, m;
cin>>n>>m;
int i, j, count = 0;;
char array[n][m];
for(i = 0; i < n; i++) {
for(j = 0; j < m; j++) {
cin>>array[i][j];
if(array[i][j] == '*')
count++;
}
}
if(count == n * m)
{
for(i = 0; i < n; i++) {
for(j = 0; j < m; j++) {
cout<<array[i][j];
}
cout<<endl;
}
}
else
{
for(i = 0; i < n; i++) {
for(j = 0; j < m; j++) {
if(array[i][j] == '?')
array[i][j] = '0';
}
}
for(i = 0; i < n; i++) {
for(j = 0; j < m; j++) {
if(array[i][j] == '0')
{
if(array[i][j+1] == '*' && i < n && j + 1 < m && i >= 0 && j + 1 >= 0)
array[i][j]++;
if(array[i][j-1] == '*' && i < n && j - 1 < m && i >= 0 && j - 1 >= 0)
array[i][j]++;
if(array[i+1][j] == '*' && i + 1 < n && j < m && i + 1 >= 0 && j >= 0)
array[i][j]++;
if(array[i-1][j] == '*' && i - 1 < n && j < m && i - 1 >= 0 && j >= 0)
array[i][j]++;
if(array[i+1][j+1] == '*' && i + 1 < n && j + 1 < m && i + 1 >= 0 && j + 1 >= 0)
array[i][j]++;
if(array[i+1][j-1] == '*' && i + 1 < n && j - 1 < m && i + 1 >= 0 && j - 1 >= 0)
array[i][j]++;
if(array[i-1][j+1] == '*' && i - 1 < n && j + 1 < m && i - 1 >= 0 && j + 1 >= 0)
array[i][j]++;
if(array[i-1][j-1] == '*' && i - 1 < n && j - 1 < m && i - 1 >= 0 && j - 1 >= 0)
array[i][j]++;
}
}
}for(i = 0; i < n; i++) {
for(j = 0; j < m; j++) {
cout<<array[i][j];
}
cout<<endl;
}
}
return 0;
} -
07 年前@
-
08 年前@
#include <cstring>
#include <iostream>
using namespace std;
char a[110][110];
int m,n;
int x[9]={0,1,1,1,0,0,-1,-1,-1};
int y[9]={0,1,0,-1,1,-1,1,0,-1};
int main()
{
cin>>m>>n;
for(int i=1;i<=m;i++) cin>>a[i]+1;
for(int i=1;i<=m;i++)
{
for(int j=1;j<=n;j++)
if(a[i][j]=='*') cout<<"*";
else
{
int flag=0;
for(int t=1;t<=8;t++)
flag+=(a[i+x[t]][j+y[t]]=='*');
cout<<flag;
}
cout<<"\n";
}
return 0;
} -
08 年前@
这里只是102和105的区别,QAQ………………………………………………………………
编译成功
测试数据 #0: RuntimeError, time = 15 ms, mem = 596 KiB, score = 0
测试数据 #1: RuntimeError, time = 15 ms, mem = 596 KiB, score = 0
测试数据 #2: RuntimeError, time = 0 ms, mem = 596 KiB, score = 0
测试数据 #3: RuntimeError, time = 15 ms, mem = 596 KiB, score = 0
测试数据 #4: RuntimeError, time = 15 ms, mem = 596 KiB, score = 0
测试数据 #5: RuntimeError, time = 0 ms, mem = 596 KiB, score = 0
测试数据 #6: RuntimeError, time = 0 ms, mem = 596 KiB, score = 0
测试数据 #7: RuntimeError, time = 0 ms, mem = 600 KiB, score = 0
测试数据 #8: RuntimeError, time = 0 ms, mem = 596 KiB, score = 0
测试数据 #9: RuntimeError, time = 0 ms, mem = 596 KiB, score = 0
RuntimeError, time = 60 ms, mem = 600 KiB, score = 0
代码
c++
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int u[9]={-10,0,1,0,-1,1,1,-1,-1},w[9]={-10,1,0,-1,0,1,-1,1,-1};
int main(void)
{
int a,b;
cin>>a>>b;
char maps[102][102];
for(int i=1;i<=a;i++)
for(int j=1;j<=b;j++)
cin>>maps[i][j];
int map[101][101];
memset(map,0,sizeof(map));
for(int i=1;i<=a;i++)
for(int j=1;j<=b;j++)
if(maps[i][j]=='*')map[i][j]=-1;
for(int i=1;i<=a;i++)
for(int j=1;j<=b;j++)
if(map[i][j]!=-1)
for(int k=1;k<=8;k++)
{
if(map[i+u[k]][j+w[k]]==-1)
map[i][j]++;
}
for(int i=1;i<=a;i++)
{
for(int j=1;j<=b;j++)
{
if(map[i][j]!=-1)cout<<map[i][j];
else cout<<"*";
}
cout<<endl;
}
return 0;
}
-----------哭泣的分割线--------------------编译成功
测试数据 #0: Accepted, time = 15 ms, mem = 616 KiB, score = 10
测试数据 #1: Accepted, time = 15 ms, mem = 616 KiB, score = 10
测试数据 #2: Accepted, time = 0 ms, mem = 616 KiB, score = 10
测试数据 #3: Accepted, time = 15 ms, mem = 620 KiB, score = 10
测试数据 #4: Accepted, time = 0 ms, mem = 620 KiB, score = 10
测试数据 #5: Accepted, time = 0 ms, mem = 612 KiB, score = 10
测试数据 #6: Accepted, time = 15 ms, mem = 616 KiB, score = 10
测试数据 #7: Accepted, time = 15 ms, mem = 616 KiB, score = 10
测试数据 #8: Accepted, time = 0 ms, mem = 616 KiB, score = 10
测试数据 #9: Accepted, time = 15 ms, mem = 612 KiB, score = 10
Accepted, time = 90 ms, mem = 620 KiB, score = 100
代码
```c++#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int u[9]={-10,0,1,0,-1,1,1,-1,-1},w[9]={-10,1,0,-1,0,1,-1,1,-1};
int main(void)
{
int a,b;
cin>>a>>b;
char maps[105][105];
for(int i=1;i<=a;i++)
for(int j=1;j<=b;j++)
cin>>maps[i][j];
int map[105][105];
memset(map,0,sizeof(map));
for(int i=1;i<=a;i++)
for(int j=1;j<=b;j++)
if(maps[i][j]=='*')map[i][j]=-1;
for(int i=1;i<=a;i++)
for(int j=1;j<=b;j++)
if(map[i][j]!=-1)
for(int k=1;k<=8;k++)
{
if(map[i+u[k]][j+w[k]]==-1)
map[i][j]++;
}
for(int i=1;i<=a;i++)
{
for(int j=1;j<=b;j++)
{
if(map[i][j]!=-1)cout<<map[i][j];
else cout<<"*";
}
cout<<endl;
}
return 0;
}
```