KK


私信TA

用户名:KinoluKaslana

访问量:1149

签 名:

等  级
排  名 42625
经  验 310
参赛次数 0
文章发表 2
年  龄 0
在职情况 学生
学  校 时间
专  业

  自我简介:

TA的其他文章

解题思路:
很简单,就是四个方向,然后每个方向再顺时针偏移一位即可修改完毕所有周围字符,这里是以四个方向作为起始点,因此在其某个方向不满足的情况下,其顺势针偏移的那一位也必不满足.
注意事项:

参考代码:

#include <iostream>
#include <vector>
#include <string>
#include <map>
int main(){
    std::vector<std::pair<int,int>> key;
    int n,m,i = 1;
    while(std::cin>>n>>m,m != 0 && n != 0){
        std::vector<std::string> map(n);
        for(int i = 0;i<n;++i){
            for(int j = 0;j<m;++j){
                char ch;
                std::cin>>ch;
                if(ch != '*')
                    ch = '0';
                else
                    key.push_back({i,j});
                map[i].push_back(ch);
            }
        }
        for(auto it:key){
            if(it.first - 1>= 0){
                if(map[it.first - 1][it.second] != '*')
                    ++map[it.first - 1][it.second];
                if(it.second + 1 < m){
                    if(map[it.first - 1][it.second + 1] != '*')
                        ++map[it.first - 1][it.second + 1];
                }
            }
            if(it.second - 1 >= 0){
                if(map[it.first][it.second - 1] != '*')
                    ++map[it.first][it.second - 1];
                if(it.first - 1 >= 0){
                    if(map[it.first - 1][it.second - 1] != '*')
                        ++map[it.first - 1][it.second - 1];
                }
            }
            if(it.first + 1 < n){
                if(map[it.first + 1][it.second] != '*')
                    ++map[it.first + 1][it.second];
                if(it.second - 1 >= 0){
                    if(map[it.first + 1][it.second - 1] != '*')
                        ++map[it.first + 1][it.second - 1];
                }
            }
            if(it.second + 1 < m){
                if(map[it.first][it.second + 1] != '*')
                    ++map[it.first][it.second + 1];
                if(it.first + 1 < n){
                    if(map[it.first + 1][it.second + 1] != '*')
                        ++map[it.first + 1][it.second + 1];
                }
            }
        }
        key.clear();
        std::cout<<"Field #"<<i<<":\n";
        for(auto it:map)
            std::cout<<it<<std::endl;
        std::cout<<std::endl;
        ++i;
    }
    return 0;
}


 

0.0分

0 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区