๋ฐ์—”์œผ๋กœ ์„ฑ์žฅ์ค‘ ๐ŸŒฑ

์•Œ๊ณ ๋ฆฌ์ฆ˜/[๋ฐฑ์ค€]

BOJ_20114 : ๋ฏธ์•„ ๋…ธํŠธ (C++)

์จ๋ฐ 2023. 2. 17. 11:18

ํ’€์ด ๋ฐฉ๋ฒ•

 

๋ฌธ์ž์—ด ๊ตฌํ˜„ ๋ฌธ์ œ์ด๋‹ค.

์ฃผ์–ด์ง„ ์—ฌ๋Ÿฌ๊ฐœ์˜ ๋ฌธ์ž์—ด๋“ค์„ ํ•œ ๋ฌธ์ž์—ด๋กœ ํ•ฉ์นœ ํ›„์— ๊ทธ ๋ฌธ์ž์—ด์—์„œ๋งŒ ํ™•์ธํ•˜๋ฉด ๋˜๋Š” ๋ฌธ์ œ์˜€๋‹ค.

 

๊ธฐ์ค€ ๋ฌธ์ž์—ด์„ ์žก์•„์ฃผ๊ณ , ๋น„๊ตํ•  ๋ฌธ์ž์—ด์—์„œ

? ์•„๋‹ˆ๋ฉด ์•ŒํŒŒ๋ฒณ์œผ๋กœ ์ด๋ฃจ์–ด์ ธ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ์ด๋ฅผ ํ™•์ธํ•˜๊ณ  ํ•ฉ์ณ์ค„ ์ˆ˜ ์žˆ๋‹ค.

 

๊ทธ ํ›„, ์ตœ์ข… ๋ฌธ์ž์—ด์—์„œ w(๊ฐ€๋กœ ๊ธธ์ด)๋งŒํผ ์ชผ๊ฐœ์„œ ํ™•์ธํ•˜๋ฉด ์‰ฝ๊ฒŒ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ๋Š” ๋ฌธ์ œ์ด๋‹ค.

 

 

 

์ฝ”๋“œ

 

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstring>
#include <stack>
#include <queue>
#include <limits.h>
#include <regex>
#include <sstream>
#include <tuple>
using namespace std;

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    // ๋ฌธ์ž์—ด ๋ณต์›ํ•˜๊ธฐ

    int n, h, w; // ๋ฌธ์ž์—ด ๊ธธ์ด, ์„ธ๋กœ ๊ธธ์ด, ๊ฐ€๋กœ ๊ธธ์ด
    cin >> n >> h >> w;

    vector <string> v; // ๋ฌธ์ž์—ด ์ €์žฅ

    string temp; // ๊ธฐ์ค€ ๋ฌธ์ž์—ด
    cin >> temp;

    for(int i = 1; i < h; i++){ // ๋น„๊ต ๋ฌธ์ž์—ด ํ™•์ธ
        string str;
        cin >> str;
        
        for(int j = 0; j < str.size(); j++){
            if(temp[j] == '?' && str[j] != '?'){
                temp[j] = str[j];
            }
        }
    }

    // cout << temp << "\n";

    string ans = "";

    for(int i = 0; i < n; i++){

        int check = 0;

        for(int j = i * w; j < i * w + w; j++){
            if(temp[j] != '?'){
                ans += temp[j];
                check = 1;
                break;
            }
        }

        if(check == 0){
            ans += '?';
        }

    }

    cout << ans << "\n";

    return 0;
}