문제
https://www.acmicpc.net/problem/5363
5363번: 요다
첫째 줄에 문장의 수 N이 주어진다. 둘째 줄부터 N개의 줄에는 각 문장이 주어진다. 문장의 길이는 100글자 이내이다. 단어의 개수는 3개 이상이다.
www.acmicpc.net
정답 코드
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
int test;
cin >> test;
cin.ignore();
for(int i = 0; i<test; i++)
{
string str;
getline(cin, str);
vector<string> vec;
stringstream ss;
ss.str(str);
string word;
while(ss>>word)
{
vec.push_back(word);
}
for(int i=2; i<vec.size(); i++)
{
cout<<vec[i]<<" ";
}
cout<<vec[0]<<" "<<vec[1]<<"\n";
}
return 0;
}
새로 알게된 것
- vector 함수와 메소드 push_back
'코딩모음zip > C++' 카테고리의 다른 글
[C++] 백준코딩 5555번: 반지 문제풀이/코드/정답/해석 (0) | 2023.02.06 |
---|