zoukankan      html  css  js  c++  java
  • day1 LGTB玩扫雷

    先附上原题:

    在一个n  m 的棋盘上,有位置上有雷(用“*” 表示),其他位置是空地(用“.” 表示)。
    LGTB 想在每个空地上写下它周围8 个方向相邻的格子中有几个雷。
    请帮助他输出写了之后的棋盘
    输入
    输入第一行包含两个整数n, m 代表棋盘大小
    接下来n 行,每行m 个字符,代表棋盘
    1  n,m  1000
    输出
    输出包含n 行,每行m 个字符,代表LGTB 写了数字之后的棋盘
    O(∩_∩)O哈!这道题,毫无算法可言就是了,纯暴力循环。。。那么,下面贴出代码:

    #include<cstdio>
    #include<cstring>
    #include<iostream>
    #include<algorithm>
    using namespace std;
    int a[1005][1005],n,m;
    char c,w='*';
    const int b[10][10]={{0,0,1,-1,1,-1,1,-1},{1,-1,0,0,1,-1,-1,1}};
    int main()
    {
    	freopen("mine.in","r",stdin);
    	freopen("mine.out","w",stdout);
    	cin>>n>>m;
    	for (int i=1;i<=n;i++)
    	 for (int j=1;j<=m;j++)
    	 {
    	 	cin>>c;
    	 	if(c=='*')
    	 	{
    	 	a[i][j]=-1;
    	 	for(int k=0;k<=7;k++)
    	 	{
    	 		if(a[i+b[0][k]][j+b[1][k]]!=-1)
    	 		a[i+b[0][k]][j+b[1][k]]++;
    	 	}
    		}
    	 }
    	 for (int i=1;i<=n;i++)
    	  for (int j=1;j<=m;j++)
    	  {
    	  	if(a[i][j]==-1)
    	  	printf("%c",w);
    	  	else
    	  	printf("%d",a[i][j]);
    	  	if(j==m)
    	  	printf("
    ");
    	  }
    	  return 0;
    }
    

      清清正正射命丸文是也~

  • 相关阅读:
    docker容器,镜像常用操作
    微信小程序登录状态
    微信小程序登录流程图
    GET和POST可传递的值到底有多大?
    php发送请求
    thinkphp 导入微信小程序加密解密库
    thinkphp 随机获取一条数据
    bootstrap row 行间距
    webstorm es6 语法报错
    Laravel
  • 原文地址:https://www.cnblogs.com/Ayateriteri/p/5671500.html
Copyright © 2011-2022 走看看