MINESWEEPER题解
来源:互联网 发布:js判断edge浏览器内核 编辑:程序博客网 时间:2024/04/28 21:17
这题也比较简单,只要先把参数从文件读出来,然后做一组判断即可,这题没有看第二遍的价值。
#include <iostream>#include <fstream>#include <string>using namespace std;string convertStr(string str, int m, int n) {int num;for(int i=0; i<m; i++) {for(int j=0; j<n; j++) {num = 0;if(str[i*n+j] == '*') continue;if(i>=1) {if(str[(i-1)*n+j] == '*') ++num;if(j>=1)if(str[(i-1)*n+j-1] == '*') ++num;if(j<n-1)if(str[(i-1)*n+j+1] == '*') ++num;}if(i<m-1) {if(str[(i+1)*n+j] == '*') ++num;if(j<n-1)if(str[(i+1)*n+j+1] == '*') ++num;if(j>=1)if(str[(i+1)*n+j-1] == '*') ++num;}if(j>=1) {if(str[i*n+j-1] == '*') ++num;}if(j<n-1){if(str[i*n+j+1] == '*') ++num;}str[i*n+j] = num+'0';}}return str;}int main (int argc, char* argv[]) {ifstream file;string lineBuffer;file.open(argv[1]);while (!file.eof()) {getline(file, lineBuffer);if (lineBuffer.length() == 0)continue; //ignore all empty lineselse {string str1, str2;int M, N;int start = lineBuffer.find_first_of(";");str1 = lineBuffer.substr(0, start);str2 = lineBuffer.substr(start+1);sscanf(str1.c_str(), "%d,%d", &M, &N);cout << convertStr(str2, M, N) << endl;}}return 0;}
0 0
- MINESWEEPER题解
- Minesweeper
- Minesweeper
- Minesweeper
- Minesweeper
- Minesweeper
- Minesweeper
- Minesweeper
- Minesweeper
- Minesweeper
- Minesweeper
- 题解——Leetcode 529. Minesweeper 难度:Medium
- 10189 - Minesweeper
- UVa10189 Minesweeper
- UVa10189 - Minesweeper
- 10189 - Minesweeper
- uva minesweeper
- 110102 MineSweeper
- GIT在Linux上的安装和使用简介
- bootstrap 和传统的html 关于button的属性问题
- DP22 堆盒子问题 Box Stacking Problem @geeksforgeeks
- Java中的null到底是啥?
- FWNX-Evaluate Reverse Polish Notation -c++ VERSION-solution accepted
- MINESWEEPER题解
- Google Code Jam Notes - Dragon Maze - Java
- DP23 Bellman–Ford Algorithm @geeksforgeeks
- Java运行时的内存模型
- 图形和函数图像的绘制
- Windows下OpenSSL创建CA证书以及客户端和服务器端证书
- 100层扔鸡蛋 2个及多个情况
- ThinkPHP的增、删、改、查
- DP24 最优BST Optimal Binary Search Tree @geeksforgeeks