반응형
[문제 풀이]
1. 번진 구역을 체크하면서 문자를 찾을 수 있다면 그 문자를 출력하고 아니면 "?"를 출력한다.
[코드]
- 번진 구역을 체크하면서 문자를 찾는다.
for(int i=0; i<N*W; i+=W){
tmp = "?";
for(int j=0; j<H; j++){
for(int k=i; k<i+W; k++){
if(arr[j][k] != '?'){
tmp = arr[j][k];
}
}
}
answer += tmp;
}
[전체 코드]
#include <iostream>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int N, H, W;
string answer, tmp, arr[11];
cin>>N>>H>>W;
for(int h=0; h<H; h++){
cin>>arr[h];
}
for(int i=0; i<N*W; i+=W){
tmp = "?";
for(int j=0; j<H; j++){
for(int k=i; k<i+W; k++){
if(arr[j][k] != '?'){
tmp = arr[j][k];
}
}
}
answer += tmp;
}
cout<<answer<<"\n";
return 0;
}
https://www.acmicpc.net/problem/20114
반응형
'Algorithm > Baekjoon' 카테고리의 다른 글
[ 백준 9037 ] The candy war (C++) (0) | 2025.03.22 |
---|---|
[ 백준 10994 ] 별 찍기 - 19 (C++) (0) | 2025.02.23 |
[ 백준 2503 ] 숫자 야구 (C++) (0) | 2025.02.15 |
[ 백준 1431 ] 시리얼 번호 (C++) (0) | 2025.02.10 |
[ 백준 1388 ] 바닥 장식 (JAVA) (0) | 2025.01.31 |