알고리즘/기타
[C++] 백준 10709번 기상캐스터
키베이루
2023. 1. 17. 13:26
1) 문제설명
2) 아이디어
입력받은 문자들중 "."은 -1로 "c"는 0으로 다시 배열에 할당하여 0이 니왔을 때 순차적으로 숫자를 증가시키는 단순한 구현 문제이다.
3) 코드
// Algo.cpp : 이 파일에는 'main' 함수가 포함됩니다. 거기서 프로그램 실행이 시작되고 종료됩니다.
//
#include <iostream>
#include<vector>
#include<algorithm>
#include <map>
using namespace std;
int h, w;
char str[101][101];
int arr[101][101];
int cnt = 1;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> h >> w;
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
cin >> str[i][j];
if (str[i][j] == 'c') {
arr[i][j] = 0;
}
else {
arr[i][j] = -1;
}
}
}
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
// 다음수가 0이면 초기화
if (arr[i][j + 1] == 0) {
cnt = 1;
}
// 현재 숫자가 0이상이면 증가
else if (arr[i][j] >= 0) {
arr[i][j + 1] = cnt++;
}
}
}
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
cout << arr[i][j] << ' ';
}
cout << '\n';
}
}
// c . . c . . c . .
// 0 1 2 0 1 2 0 1 2