题解

53 条题解

  • 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.

  • 0
    @ 2016-05-30 13:51:27

    var
    a:array[0..101,0..101] of char;
    n,m,i,j,t: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.

  • 0
    @ 2016-05-30 13:50:07

    var
    a:array[0..101,0..101] of char;
    n,m,i,j,t: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.

  • 0
    @ 2016-05-30 13:19:40

    program P1975;
    var
    a:array[0..101,0..101] of char;
    i,j,k,n,m:integer;
    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
    begin
    for j:=0 to m+1 do
    if a[i,j]<>'*' then a[i,j]:='0';
    end;
    for i:=1 to n do
    begin
    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;
    end;
    for i:=1 to n do
    begin
    for j:=1 to m do
    write(a[i,j]);
    writeln;
    end;
    end.

  • 0
    @ 2016-05-30 13:12:22

    program P1975;
    var
    a:array[0..101,0..101] of char;
    i,j,k,n,m:integer;
    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
    begin
    for j:=0 to m+1 do
    if a[i,j]<>'*' then a[i,j]:='0';
    end;
    for i:=1 to n do
    begin
    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;
    end;
    for i:=1 to n do
    begin
    for j:=1 to m do
    write(a[i,j]);
    writeln;
    end;
    end.

  • 0
    @ 2016-05-27 13:48:10

    program P1975;
    var
    a:array[0..101,0..101] of char;
    i,j,k,n,m:integer;
    begin
    read(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
    begin
    for j:=0 to m+1 do
    if a[i,j]<>'*' then a[i,j]:='0';
    end;
    for i:=1 to n do
    begin
    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;
    end;
    for i:=1 to n do
    begin
    for j:=1 to m do
    write(a[i,j]);
    writeln;
    end;
    end.

  • 0
    @ 2016-05-17 22:04:25

    include <stdio.h>

    char a[105][105];
    int b[105][105];

    int main (void)
    {

    int n, m, i, j;
    scanf("%d%d",&n,&m);
    getchar();
    for (i=1; i<=n; i++) {
    for (j=1; j<=m; j++) {
    a[i][j] = getchar();
    if (a[i][j] == '*') {
    b[i-1][j-1]++;
    b[i-1][j]++;
    b[i-1][j+1]++;
    b[i][j-1]++;
    b[i][j+1]++;
    b[i+1][j-1]++;
    b[i+1][j]++;
    b[i+1][j+1]++;
    }
    }
    getchar();
    }
    for (i=1; i<=n; i++) {
    for (j=1; j<=m; j++) {
    if (a[i][j] == '*')
    putchar('*');
    else
    printf("%d",b[i][j]);
    }
    putchar('\n');
    }
    return 0;
    }

  • 0
    @ 2016-03-30 15:37:01

    var
    m,n,i,j,ans:longint;
    a:array[0..101,0..101] of char;
    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
    if a[i,j]='*' then write('*')
    else begin
    ans:=0;
    if a[i-1,j]='*' then inc(ans);
    if a[i-1,j-1]='*' then inc(ans);
    if a[i,j-1]='*' then inc(ans);
    if a[i+1,j]='*' then inc(ans);
    if a[i,j+1]='*' then inc(ans);
    if a[i+1,j+1]='*' then inc(ans);
    if a[i-1,j+1]='*' then inc(ans);
    if a[i+1,j-1]='*' then inc(ans);
    write(ans);
    end;
    writeln;
    end;
    end.

  • 0
    @ 2016-03-23 17:19:45

    QWQ#include <iostream>
    using namespace std;
    char a[101][101];
    char x[101][101];
    int msum(int x,int y)
    { char count='0';
    if(a[x+1][y]=='*') count+=1;
    if(a[x-1][y]=='*') count+=1;
    if(a[x][y+1]=='*') count+=1;
    if(a[x][y-1]=='*') count+=1;
    if(a[x+1][y+1]=='*') count+=1;
    if(a[x+1][y-1]=='*') count+=1;
    if(a[x-1][y+1]=='*') count+=1;
    if(a[x-1][y-1]=='*') count+=1;
    return count;
    }
    int main()
    {int b,c,d,e,f,g;
    cin>>b>>c;
    for(int i=1;i<=b;i++)
    for(int j=1;j<=c;j++)
    cin>>a[i][j];
    for(int i=1;i<=b;i++)
    for(int j=1;j<=c;j++)
    {if(a[i][j]=='*') x[i][j]='*';
    if(a[i][j]=='?') x[i][j]=msum(i,j);
    }
    for(int i=1;i<=b;i++)
    {for(int j=1;j<=c;j++)
    cout<<x[i][j];
    cout<<endl;
    }
    }

  • 0
    @ 2016-03-11 07:19:16

    #include <iostream>
    using namespace std;
    char a[101][101];
    char x[101][101];
    int msum(int x,int y)
    { char count='0';
    if(a[x+1][y]=='*') count+=1;
    if(a[x-1][y]=='*') count+=1;
    if(a[x][y+1]=='*') count+=1;
    if(a[x][y-1]=='*') count+=1;
    if(a[x+1][y+1]=='*') count+=1;
    if(a[x+1][y-1]=='*') count+=1;
    if(a[x-1][y+1]=='*') count+=1;
    if(a[x-1][y-1]=='*') count+=1;
    return count;
    }
    int main()
    {int b,c,d,e,f,g;
    cin>>b>>c;
    for(int i=1;i<=b;i++)
    for(int j=1;j<=c;j++)
    cin>>a[i][j];
    for(int i=1;i<=b;i++)
    for(int j=1;j<=c;j++)
    {if(a[i][j]=='*') x[i][j]='*';
    if(a[i][j]=='?') x[i][j]=msum(i,j);
    }
    for(int i=1;i<=b;i++)
    {for(int j=1;j<=c;j++)
    cout<<x[i][j];
    cout<<endl;
    }
    }

  • 0
    @ 2016-01-02 14:40:05

    #include <ctime>
    #include <cstdlib>
    #include <iostream>
    using namespace std;
    int map[12][12]; // 为避免边界的特殊处理,故将二维数组四周边界扩展1
    int derection[3] = { 0, 1, -1 }; //方向数组
    int calculate ( int x, int y )
    {
    int counter = 0;
    for ( int i = 0; i < 3; i++ )
    for ( int j = 0; j < 3; j++ )
    if ( map[ x+derection[i]][ y+derection[j] ] == 9 )
    counter++; // 统计以(x,y)为中心的四周的雷数目
    return counter;
    }
    void game ( int x, int y )
    {
    if ( calculate ( x, y ) == 0 )
    {
    map[x][y] = 0;
    for ( int i = 0; i < 3; i++ )
    { // 模拟游戏过程,若点到一个空白,则系统自动向外扩展
    for ( int j = 0; j < 3; j++ )
    if ( x+derection[i] <= 9 && y+derection[j] <= 9 && x+derection[i] >= 1 && y+derection[j] >= 1
    && !( derection[i] == 0 && derection[j] == 0 ) && map[x+derection[i]][y+derection[j]] == -1 )
    game( x+derection[i], y+derection[j] ); // 条件比较多,一是不可以让两个方向坐标同时为0,否则
    递归调用本身!
    } //二是递归不能出界.三是要保证不返回调用。
    }
    else
    map[x][y] = calculate(x,y);
    }
    void print ()
    {
    for ( int i = 1; i < 10; i++ )
    {
    for ( int j = 1; j < 10; j++ )
    {
    if ( map[i][j] == -1 || map[i][j] == 9 )
    cout << "#";
    else
    cout << map[i][j];
    }
    cout << endl;
    }
    }
    bool check ()
    {
    int counter = 0;
    for ( int i = 1; i < 10; i++ )
    for ( int j = 1; j < 10; j++ )
    if ( map[i][j] != -1 )
    counter++;
    if ( counter == 10 )
    return true;
    else
    return false;
    }

    int main ()
    {

    int i, j, x, y;
    char ch;
    srand ( time ( 0 ) );

    do
    {
    memset ( map, -1, sizeof(map) ); // 将map全部初始化为-1,以后用-1表示未涉及的区域

    for ( i = 0; i < 10; )
    {
    x = rand()%9 + 1;
    y = rand()%9 + 1;
    if ( map[x][y] != 9 )
    {
    map[x][y] = 9;
    i++;
    }
    }

    for ( i = 1; i < 10; i++ )
    {
    for ( j = 1; j < 10; j++ )
    cout << "#";
    cout << "\n";
    }
    cout << "\n";

    cout << "Please enter a coordinate: ";
    while ( cin >> x >> y )
    {
    if ( map[x][y] == 9 )
    {
    cout << "GAME OVER" << endl; //点中雷之后游戏结束,并且输出雷的位置
    for ( i = 1; i < 10; i++ )
    {
    for ( j = 1; j < 10; j++ )
    {
    if ( map[i][j] == 9 )
    cout << "@";
    else
    cout << "#";
    }
    cout << endl;
    }
    break;
    }

    game(x,y);
    print();

    if ( check () )
    {
    cout << "YOU WIN" << endl;
    break;
    }
    cout << "\n\n";
    }

    cout << "Do you want to play again, if true enter Y, or enter N" << endl;
    cin >> ch;
    cout << "\n\n";
    } while ( ch == 'Y' );

    return 0;
    }

  • 0
    @ 2015-12-21 15:45:16

    Code

    var
    l:array[1..200,1..200]of char;
    i,j,k,m,n:longint;
    ip,op:text;
    begin

    readln(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.

  • 0
    @ 2015-12-15 00:18:59

    C Code

    #include<stdio.h>
    char range[100][100]={{'\0'}};
    int n,m;
    char Detect(int y,int x)
    {
    int i='0';
    if((y-1>=0)&&(x-1>=0)&&(range[y-1][x-1]=='*'))
    i++;
    if((y-1>=0)&&(range[y-1][x]=='*'))
    i++;
    if((y-1>=0)&&(x+1<=m)&&(range[y-1][x+1]=='*'))
    i++;
    if((x-1>=0)&&(range[y][x-1]=='*'))
    i++;
    if((x+1<=m)&&(range[y][x+1]=='*'))
    i++;
    if((y+1<=n)&&(x-1>=0)&&(range[y+1][x-1]=='*'))
    i++;
    if((y+1<=n)&&(range[y+1][x]=='*'))
    i++;
    if((y+1<=n)&&(x+1<=m)&&(range[y-1][x+1]=='*'))
    i++;
    return i;
    }
    int main()
    {
    int i,j;
    scanf("%d %d\n",&n,&m);
    n--;
    m--;
    for(j=0;j<=n;j++)
    scanf("%s",range[j]);
    for(j=0;j<=n;j++)
    for(i=0;i<=m;i++)
    if(range[j][i]=='?')
    range[j][i]=Detect(j,i);
    for(j=0;j<=n;j++)
    {
    for(i=0;i<=m;i++)
    printf("%c",range[j][i]);
    printf("\n");
    }
    return 0;
    }

  • 0
    @ 2015-12-10 18:37:46

    var b:array[0..101,0..101] of longint;
    a:array[0..101,0..101] of char;
    n,m,i,j:longint;
    begin
    assign(input,'mine.in'); reset(input);
    assign(output,'mine.out');rewrite(output);
    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+1,j]='*' then b[i,j]:=b[i,j]+1;
    if a[i-1,j]='*' then b[i,j]:=b[i,j]+1;
    if a[i,j+1]='*' then b[i,j]:=b[i,j]+1;
    if a[i,j-1]='*' then b[i,j]:=b[i,j]+1;
    if a[i+1,j+1]='*' then b[i,j]:=b[i,j]+1;
    if a[i-1,j-1]='*' then b[i,j]:=b[i,j]+1;
    if a[i-1,j+1]='*' then b[i,j]:=b[i,j]+1;
    if a[i+1,j-1]='*' then b[i,j]:=b[i,j]+1;
    if a[i,j]='*' then b[i,j]:=-20;
    end;

    for i:=1 to n do
    begin
    for j:=1 to m do
    begin
    if b[i,j]>-1 then write(b[i,j]);
    if b[i,j]=-20 then write('*');
    end;
    writeln;
    end;
    close(input);close(output);
    end.

  • 0
    @ 2015-12-05 13:10:07

    program mine1;
    label
    438;
    var
    map:array[0..101,0..101] of char;
    num:array[1..100,1..100] of 0..8;
    lin:array[1..100] of string;
    m,n,a,b,mine,temp:longint;
    begin
    readln(m,n);
    for a:=1 to n do
    for b:=1 to m do
    438:
    begin
    read(map[a,b]);
    if not((map[a,b]='?') or (map[a,b]='*'))
    then goto 438;
    end;
    for a:=1 to n do
    begin
    for b:=1 to m do
    if map[a,b]='?' then
    begin
    mine:=0;
    if map[a-1,b-1]='*' then mine:=mine+1;
    if map[a+1,b-1]='*' then mine:=mine+1;
    if map[a+1,b+1]='*' then mine:=mine+1;
    if map[a-1,b+1]='*' then mine:=mine+1;
    if map[a-1,b]='*' then mine:=mine+1;
    if map[a+1,b]='*' then mine:=mine+1;
    if map[a,b-1]='*' then mine:=mine+1;
    if map[a,b+1]='*' then mine:=mine+1;
    num[a,b]:=mine;
    end;
    end;
    for a:=1 to n do
    begin
    for b:=1 to m do
    if map[a,b]='*' then
    write('*')
    else
    write(num[a,b]);
    writeln;
    end;
    end.
    不过在这评测满分,NOIP却80分

  • 0
    @ 2015-12-02 16:37:25

    program p1975;
    var
    m,n,i,j,k:longint;
    a:array[0..101,0..101] of char;
    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
    if a[i,j]='*' then write('*')
    else
    begin
    k:=0;
    if a[i-1,j]='*' then k:=k+1;
    if a[i-1,j-1]='*' then k:=k+1;
    if a[i,j-1]='*' then k:=k+1;
    if a[i+1,j]='*' then k:=k+1;
    if a[i,j+1]='*' then k:=k+1;
    if a[i+1,j+1]='*' then k:=k+1;
    if a[i-1,j+1]='*' then k:=k+1;
    if a[i+1,j-1]='*' then k:=k+1;
    write(k);
    end;
    writeln;
    end;
    end.

  • 0
    @ 2015-12-02 16:35:41

    真希望回到普及组
    program p1975;
    var a:array[0..105,0..105] of char;
    i,m,n,j,sum: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
    if a[i,j]='*' then write('*')
    else

    begin
    sum:=0;

    if a[i-1,j-1]='*' then inc(sum);
    if a[i,j-1]='*' then inc(sum);
    if a[i+1,j-1]='*' then inc(sum);
    if a[i-1,j+1]='*' then inc(sum);
    if a[i-1,j]='*' then inc(sum);
    if a[i+1,j]='*' then inc(sum);
    if a[i,j+1]='*' then inc(sum);
    if a[i+1,j+1]='*' then inc(sum);
    write(sum);
    end;
    writeln;
    end;
    end.

信息

ID
1975
难度
4
分类
模拟 点击显示
标签
递交数
2822
已通过
1091
通过率
39%
被复制
22
上传者