Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- 우선순위 큐
- 문자열
- c++
- 자료구조
- 정렬
- 알고리즘
- 브루트포스
- 투 포인터
- Team Fortress 2
- 재귀
- 트리
- 유니온 파인드
- Unreal Engine 5
- DFS
- BFS
- 백준
- 그래프
- XR Interaction Toolkit
- 다이나믹 프로그래밍
- VR
- 그리디 알고리즘
- 다익스트라
- 스택
- 시뮬레이션
- 구현
- ue5
- 누적 합
- 수학
- 유니티
- 백트래킹
Archives
- Today
- Total
1일1알
백준 4108번 지뢰찾기 C++ 본문
https://www.acmicpc.net/problem/4108
4108번: 지뢰찾기
C개의 문자들이 포함된 R개의 줄을 출력한다. 단, 모든 '.' 대신 인접한 칸에 위치한 지뢰의 수로 변경해 출력한다. '*' 칸은 그대로 출력한다. 문자 사이에 공백이나 줄 사이에 공백 줄이 있어선
www.acmicpc.net
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <set>
#include <map>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <limits.h>
using namespace std;
using int64 = long long;
int dRow[8] = { -1,-1, 0, 1, 1, 1, 0,-1 };
int dCol[8] = { 0, 1, 1, 1, 0,-1,-1,-1 };
vector<vector<char>> board;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int r, c;
while (true) {
cin >> r >> c;
if (r == 0 && c == 0) break;
board = vector<vector<char>>(r, vector<char>(c));
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
cin >> board[i][j];
}
}
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
if (board[i][j] == '*') continue;
int cnt = 0;
for (int k = 0; k < 8; k++) {
int nextRow = i + dRow[k];
int nextCol = j + dCol[k];
if (nextRow < 0 || nextRow >= r) continue;
if (nextCol < 0 || nextCol >= c) continue;
if (board[nextRow][nextCol] != '*') continue;
cnt++;
}
board[i][j] = cnt + 48;
}
}
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
cout << board[i][j];
}
cout << "\n";
}
}
};
'알고리즘' 카테고리의 다른 글
백준 3060번 욕심쟁이 돼지 C++ (0) | 2023.05.03 |
---|---|
백준 2799번 블라인드 C++ (0) | 2023.05.02 |
백준 23843번 콘센트 C++ (0) | 2023.04.29 |
백준 5464번 주차장 C++ (0) | 2023.04.28 |
백준 1448번 삼각형 만들기 C++ (0) | 2023.04.26 |