Notice
Recent Posts
Recent Comments
Link
Little Jay
[C++] 백준 9093번 - 단어 뒤집기 본문
string을 잘 split하고 reverse 하면 풀 수 있는 문제
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
using namespace std;
vector<string> split(string input, char delimiter) {
vector<string> answer;
stringstream ss(input);
string temp;
while (getline(ss, temp, delimiter)) {
answer.push_back(temp);
}
return answer;
}
int main() {
int n;
cin >> n;
cin.ignore();
for (int i = 0; i < n; i++) {
string s;
getline(cin, s);
vector<string> v = split(s, ' ');
for (int i = 0; i < v.size(); i++) {
reverse(v[i].begin(), v[i].end());
cout << v[i] << " ";
}
cout << "\n";
}
return 0;
}'알고리즘 > BOJ' 카테고리의 다른 글
| [C++] 백준 1850번 - 최대공약수 (0) | 2021.08.21 |
|---|---|
| [C++] 백준 5430번 틀 (0) | 2021.08.20 |
| [C++] 백준 2606번 - 바이러스 (0) | 2021.08.19 |
| [C++] 백준 11724번 - 연결 요소의 개수 (0) | 2021.08.19 |
| [C++] 백준 1260번 - DFS와 BFS (0) | 2021.08.19 |
Comments