본문 바로가기

Algorithm_BOJ(백준)/문자열

[백준 10798 c++ O] 세로읽기

728x90
반응형

- 풀이 링크:

https://github.com/xhaktmchl/Algorithm_study/blob/main/BOJ/%EB%AC%B8%EC%9E%90%EC%97%B4/%5B%EB%B0%B1%EC%A4%80%2010798%20c%2B%2B%20O%5D%20%EC%84%B8%EB%A1%9C%EC%9D%BD%EA%B8%B0.cpp

 

GitHub - xhaktmchl/Algorithm_study: 알고리즘 이론 및 문제풀이

알고리즘 이론 및 문제풀이. Contribute to xhaktmchl/Algorithm_study development by creating an account on GitHub.

github.com

#include <iostream>
#include <algorithm>
//#include <map> // 중복 x 
#include <string> // getline
//#include <cstring> // memset, strok, strstr
//#include <vector>
//#include <queue>
//#include <set> // 트리, 중복 x
//#include <unordered_set>
using namespace std;
/*
[백준 10798 c++ O] 세로읽기
접근1: 
시간복잡도: n*n
풀이: 
    //1.입력
    //2.문자열 탐색
*/
char a[20][20];
string str;
int maxSize = -1;

int main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(0);
    
    //1.입력
    for (int i = 0; i < 5; i++) {
        cin >> str;
        int size = str.size();
        if (size > maxSize) maxSize = size;
        for (int j = 0; j < size; j++) {
            a[i][j] = str[j];
        }
    }
    //2.문자열 탐색
    for (int j = 0; j < maxSize; j++) {
        for (int i = 0; i < 5; i++) {
            if (a[i][j] != 0) {
                cout << a[i][j];
            }
        }
    }
    return 0;
}
반응형