[PS 백준 - 1.9] 10798번: 세로 읽기
문제 정보
- 난이도: 브론즈 1
 - 알고리즘: 문자열, 큐
 
코멘트
이 문제는 큐와 벡터를 이용해서 풀어보았다. 길이가 안맞는 부분은단순히 문자열로 접근해도 되지만 나는 큐에서 다음과 같이 코드를 작성하여 단어를 꺼낼지 말지 결정해서 풀어보았다.
if (!quevec[i].empty()) {
	cout << quevec[i].front();
	quevec[i].pop();
}
소스 코드
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <string>
using namespace std;
int main() {
	cin.tie(NULL);
	cout.tie(NULL);
	std::ios::sync_with_stdio(false);
	string str;
	int max = 0;
	vector<queue<char>> quevec;
	for (int i = 0; i < 5; i++) {
		cin >> str;
		queue<char> que;
		for (char c : str) {
			que.push(c);
		}
		max = max > que.size() ? max : que.size();
		quevec.push_back(que);
	}
	for (int j = 0; j < max; j++) {
		for (int i = 0; i < 5; i++) {
			if (!quevec[i].empty()) {
				cout << quevec[i].front();
				quevec[i].pop();
			}
		}
	}
}
                Author And Source
이 문제에 관하여([PS 백준 - 1.9] 10798번: 세로 읽기), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@yjwon20/PSboj1-9저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
                                
                                
                                
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)