coding_test/BAEKJOON
백준 9093번 C++ 풀이
CodeJin
2022. 1. 2. 16:39
https://www.acmicpc.net/problem/9093
9093번: 단어 뒤집기
첫째 줄에 테스트 케이스의 개수 T가 주어진다. 각 테스트 케이스는 한 줄로 이루어져 있으며, 문장이 하나 주어진다. 단어의 길이는 최대 20, 문장의 길이는 최대 1000이다. 단어와 단어 사이에는
www.acmicpc.net

문장을 입력받고, 각 단어를 뒤집어 출력하는 문제. 문자를 입력받은 후에 공백을 기준으로 파싱하고 뒤집어 출력한다.
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t;
string str;
string token;
cin >> t;
cin.ignore();
while (t--) {
getline(cin, str);
stringstream sstream(str);
while (getline(sstream, token, ' ')) {
reverse(token.begin(), token.end());
cout << token << ' ';
}
cout << '\n';
}
}
