- 난이도: 브론즈 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();
}
}
}
}