题解

50 条题解

  • 4
    @ 2017-10-04 00:17:00

    直接覆盖上去玩了。
    #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;
    }

  • 2
    @ 2016-11-16 16:01:03

    #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;
    }


  • 1
    @ 2018-08-20 09:23:54
    /*
    水题啊
    直接乱搞不就好了
    对于每一个点
    我们来直接对于每一个点
    就直接搜索一下八个方向个数就好
    水题Orz
    */
    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <cstring>
    using namespace std;
    
    const int MAXN=105;
    int n,m;
    int a[MAXN][MAXN];
    int zx[8][2]={{-1,0},{-1,-1},{1,1},{0,-1},{1,0},{-1,1},{1,-1},{0,1}};
    
    void init()
    {
        char ch;
        cin>>n>>m;
        for(int i=1;i<=n;i++)
            for(int j=1;j<=m;j++)
            {
                cin>>ch;
                if(ch=='*')
                    a[i][j]=-1;
            }
    }
    
    int gets(int x,int y)
    {
        int ans=0;
        for(int i=0;i<8;i++)
        {
            int newx=x+zx[i][0];
            int newy=y+zx[i][1];
            if(newx>n||newy>m||newx<1||newy<1)
                continue;
            if(a[newx][newy]==-1)
                ans++;
        }
        return ans;
    }
    
    int main()
    {
        init();
        for(int i=1;i<=n;i++)
            for(int j=1;j<=m;j++)
                if(a[i][j]!=-1)
                    a[i][j]=gets(i,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;
        }
    }
         
    
  • 1
    @ 2017-10-02 21:45:56

    #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;
    }

  • 1
    @ 2017-01-23 00:50:25

    #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;
    }

  • 1
    @ 2016-11-11 22:03:48
    var
      n,m,i,j:longint;
      a,b:array[1..100,1..100] of char;
    begin
      fillchar(b,sizeof(b),'0');
      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
        for j:=1 to m do
          begin
            if a[i,j] = '?' then
              begin
                if j <> 1 then
                  if a[i,j-1] = '*' then
                    b[i,j]:=chr(ord(b[i,j])+1); //left
                if (i <> 1) and (j <> 1) then
                  if a[i-1,j-1] = '*' then
                    b[i,j]:=chr(ord(b[i,j])+1); //left up
                if i <> 1 then
                  if a[i-1,j] = '*' then
                    b[i,j]:=chr(ord(b[i,j])+1); //up
                if (i <> 1) and (j <> m) then
                  if a[i-1,j+1] = '*' then
                    b[i,j]:=chr(ord(b[i,j])+1); //right up
                if j <> m then
                  if a[i,j+1] = '*' then
                    b[i,j]:=chr(ord(b[i,j])+1); //right
                if (i <> n) and (j <> m) then
                  if a[i+1,j+1] = '*' then
                    b[i,j]:=chr(ord(b[i,j])+1); //right down
                if i <> n then
                  if a[i+1,j] = '*' then
                    b[i,j]:=chr(ord(b[i,j])+1); //down
                if (i <> n) and (j <> 1) then
                  if a[i+1,j-1] = '*' then
                    b[i,j]:=chr(ord(b[i,j])+1); //left down
              end;
           if a[i,j] = '*' then
             b[i,j]:='*';
          end;
      for i:=1 to n do
        begin
          for j:=1 to m do
            write(b[i,j]);
          writeln;
        end;
    end.
    
  • 1
    @ 2016-11-02 13:14:31

    #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;
    }

  • 1
    @ 2016-10-28 19:50:00

    #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

  • 1
    @ 2016-10-14 13:58:57

    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.

  • 1
    @ 2016-10-02 11:21:25

    #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;
    }

  • 1
    @ 2016-09-04 19:47:34

    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.
    比赛现场打的,好傻啊。。。

  • 0
    @ 2018-06-21 15:22:59

    #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;
    }

  • 0
    @ 2018-06-19 19:36:36
    #include<iostream>
    using namespace std;
    int main()
    {
        int n,m,map[102][102]={0};
        char tmp;
        cin>>n>>m;
        for (int h=1;h<=n;h++)
            for (int l=1;l<=m;l++)
            {
                cin>>tmp;
                if (tmp=='*')
                    map[h][l]=1;
            }
        for (int h=1;h<=n;h++)
        {
            for (int l=1;l<=m;l++)
            {
                if (map[h][l]==1)
                    cout<<'*';
                else
                {
                    int tot=0;
                    for (int lh=h-1;lh<=h+1;lh++)
                        for (int ll=l-1;ll<=l+1;ll++)
                            if (map[lh][ll]==1)
                                tot++;
                    cout<<tot;
                }               
            }
            cout<<endl;
        }
        
        return 0;
    }
    
  • 0
    @ 2017-06-04 13:01:17

    #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;
    }

  • 0
    @ 2016-08-25 12:37:45

    这里只是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;
    }

    ```

  • 0
    @ 2016-08-22 18:25:34

    好理解到炸
    #include<bits/stdc++.h>
    using namespace std;
    int main()
    {
    int m,n,i,j,k,ni,nj,_map[101][101]={0};
    int dx[8]={0,0,1,-1,1,1,-1,-1};
    int dy[8]={1,-1,0,0,1,-1,1,-1};
    bool flag[101][101];
    char ch;
    memset(flag,true,sizeof(flag));
    cin>>m>>n;
    for(i=1;i<=m;i++)
    for(j=1;j<=n;j++)
    {
    cin>>ch;
    if(ch=='*')
    {
    flag[i][j]=false;
    _map[i][j]=9;
    }
    }
    for(i=1;i<=m;i++)
    for(j=1;j<=n;j++)
    if(flag[i][j])
    {
    for(k=0;k<9;k++)
    {
    ni=i+dx[k];
    nj=j+dy[k];
    if(ni>=1&&ni<=m&&nj>=1&&nj<=n&&flag[ni][nj]==false)
    _map[i][j]++;
    }
    }
    for(i=1;i<=m;i++)
    {
    for(j=1;j<=n;j++)
    if(flag[i][j]) cout<<_map[i][j];
    else cout<<"*";
    cout<<endl;
    }

    return 0;
    }

  • 0
    @ 2016-07-20 21:47:58

    #include<iostream>
    using namespace std;
    char a[103][103];
    int b[103][103]={0},c[103][103]={0};
    int main()
    {
    int n,m,t=0;
    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]=='*')
    b[i][j]=1;
    for(int i=1;i<=n;++i)
    for(int j=1;j<=m;++j)
    {
    if(b[i+1][j]==1)
    {
    c[i][j]++;
    }
    if(b[i+1][j+1]==1)
    {
    c[i][j]++;
    }
    if(b[i][j+1]==1)
    {
    c[i][j]++;
    }
    if(b[i][j-1]==1)
    {
    c[i][j]++;
    }
    if(b[i-1][j]==1)
    {
    c[i][j]++;
    }
    if(b[i-1][j-1]==1)
    {
    c[i][j]++;
    }
    if(b[i+1][j-1]==1)
    {
    c[i][j]++;
    }
    if(b[i-1][j+1]==1)
    {
    c[i][j]++;
    }
    }
    for(int i=1;i<=n;++i)
    for(int j=1;j<=m;++j)
    {
    if(b[i][j]==0)
    cout<<c[i][j];
    else
    cout<<"*";
    t++;
    if(t==m)
    {
    cout<<endl;
    t=0;
    }
    }
    return 0;
    }
    看起来庞大实际很好理解

  • 0
    @ 2016-07-04 15:01:53

    C:
    测试数据 #0: Accepted, time = 0 ms, mem = 500 KiB, score = 10
    测试数据 #1: Accepted, time = 0 ms, mem = 496 KiB, score = 10
    测试数据 #2: Accepted, time = 15 ms, mem = 504 KiB, score = 10
    测试数据 #3: Accepted, time = 15 ms, mem = 500 KiB, score = 10
    测试数据 #4: Accepted, time = 0 ms, mem = 500 KiB, score = 10
    测试数据 #5: Accepted, time = 15 ms, mem = 496 KiB, score = 10
    测试数据 #6: Accepted, time = 0 ms, mem = 500 KiB, score = 10
    测试数据 #7: Accepted, time = 15 ms, mem = 500 KiB, score = 10
    测试数据 #8: Accepted, time = 0 ms, mem = 496 KiB, score = 10
    测试数据 #9: Accepted, time = 0 ms, mem = 500 KiB, score = 10
    Accepted, time = 60 ms, mem = 504 KiB, score = 100

    代码如下:
    #include <stdio.h>
    char A[101][101];
    int xx[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
    int yy[8] = { 0, -1,-1,-1, 0, 1, 1, 1};
    int n, m;

    int PD(int x, int y) {
    if(x>0 && x<=n && y>0 && y<=m) return 1;
    return 0;
    }

    int main() {
    int i, j, k, sum;
    scanf("%d %d", &n, &m);
    for(i=1; i<=n; i++){
    scanf("\n");
    for(j=1; j<=m; j++)
    scanf("%c", &A[i][j]);
    }

    for(i=1; i<=n; i++) {
    for(j=1; j<=m; j++) {
    if(A[i][j] == '?') {
    sum=0;
    for(k=0; k<8; k++) {
    int x = i + xx[k];
    int y = j + yy[k];
    if(PD(x,y) == 1) {
    if(A[x][y] == '*')
    sum++;
    }
    }
    A[i][j] = sum;
    }
    }
    }

    for(i=1; i<=n; i++) {
    for(j=1; j<=m; j++) {
    if(A[i][j] == '*') printf("%c", '*');
    else printf("%d", A[i][j]);
    }
    printf("\n");
    }
    return 0;
    }

  • 0
    @ 2016-07-02 08:51:49

    读入时一定要换行,不然读不成功
    var
    i,j,ii,jj,n,m:longint;
    a,b:array[0..110,0..110] of longint;
    x:char;
    begin
    readln(n,m);
    for i:=1 to n do
    begin
    for j:=1 to m do
    begin
    read(x);
    if x='*' then a[i,j]:=1
    else a[i,j]:=0;
    end;
    readln;
    end;
    for i:=1 to n do
    begin
    for j:=1 to m do
    begin
    if a[i,j]=1 then write('*')
    else for ii:=i-1 to i+1 do
    for jj:=j-1 to j+1 do
    if a[ii,jj]=1 then inc(b[i,j]);
    if a[i,j]<>1 then write(b[i,j]);
    end;
    writeln;
    end;
    end.

  • 0
    @ 2016-06-10 21:14:27

    做了5次才做出来(⊙﹏⊙)b

    测试数据 #0: Accepted, time = 31 ms, mem = 812 KiB, score = 10

    测试数据 #1: Accepted, time = 62 ms, mem = 812 KiB, score = 10

    测试数据 #2: Accepted, time = 46 ms, mem = 812 KiB, score = 10

    测试数据 #3: Accepted, time = 46 ms, mem = 812 KiB, score = 10

    测试数据 #4: Accepted, time = 31 ms, mem = 812 KiB, score = 10

    测试数据 #5: Accepted, time = 15 ms, mem = 816 KiB, score = 10

    测试数据 #6: Accepted, time = 31 ms, mem = 816 KiB, score = 10

    测试数据 #7: Accepted, time = 31 ms, mem = 812 KiB, score = 10

    测试数据 #8: Accepted, time = 31 ms, mem = 812 KiB, score = 10

    测试数据 #9: Accepted, time = 15 ms, mem = 812 KiB, score = 10

    Accepted, time = 339 ms, mem = 816 KiB, score = 100

    var

    a:array[0..101,0..101] of char;
    n,m,i,j,k: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:=0 to n+1 do
    for j:=0 to m+1 do
    if a[i,j]<>'*' then a[i,j]:='0';

    for i:=1 to n do
    for j:=1 to m do
    if a[i,j]='*' then
    begin
    if a[i-1,j]<>'*' then inc(a[i-1,j]);
    if a[i+1,j]<>'*' then inc(a[i+1,j]);
    if a[i,j-1]<>'*' then inc(a[i,j-1]);
    if a[i,j+1]<>'*' then inc(a[i,j+1]);
    if a[i-1,j-1]<>'*' then inc(a[i-1,j-1]);
    if a[i-1,j+1]<>'*' then inc(a[i-1,j+1]);
    if a[i+1,j-1]<>'*' then inc(a[i+1,j-1]);
    if a[i+1,j+1]<>'*' then inc(a[i+1,j+1]);
    end;
    for i:=1 to n do
    begin
    for j:=1 to m do
    write(a[i,j]);
    writeln;
    end;
    end.

信息

ID
1975
难度
4
分类
模拟 点击显示
标签
递交数
2507
已通过
1004
通过率
40%
上传者