[백준] 10798번 세로읽기 / C++
#문제
#풀이
#include <iostream>
#include <vector>
#include <string>
using namespace std;
vector<string> words;
vector<char> ans;
int main()
{
ios::sync_with_stdio(false); cin.tie(NULL);
for (int i = 0; i < 5; ++i)
{
string word;
cin >> word;
words.push_back(word);
words[i].resize(15);
}
for (int i = 0; i < 15; ++i)
{
for (int j = 0; j < 5; ++j)
{
if ((words[j][i] >= 48 && words[j][i] <= 57) || (words[j][i] >= 65 && words[j][i] <= 90) || (words[j][i] >= 97 && words[j][i] <= 122))
{
ans.push_back(words[j][i]);
}
}
}
for (int i = 0; i < ans.size(); ++i)
{
cout << ans[i];
}
return 0;
}
#정리
1보다 크고 15보다 작은 수로 구성된 단어를 5개 받고, 각 단어의 첫 번째 문자부터 차례대로 출력하는 문제다. 해당 문제의 이슈는 공백이다. 공백이 일어나지 않도록 단어를 받고, 공백은 벡터의 메소드인 .resize를 사용해서 15개로 꽉꽉 채워줬다. 그리고 아스키 코드 0-9, A-Z, a-z 이내의 코드일 경우에만 ans벡터에 받고, 마지막에 ans의 용량만큼 출력했다.
Enjoy Reading This Article?
Here are some more articles you might like to read next: