문제 : https://www.acmicpc.net/problem/9093


[알고리즘풀이]

getline 함수를 이용해 띄어쓰기까지 포함해서 입력을 받고, buffer flush를 이용해 buffer를 비워준다.

#include<iostream>
#include<string>
#include<vector>

using namespace std;

int main(void) {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int t;
	cin >> t;
	string bufferflush;
	getline(cin, bufferflush);
	while (t--) {
		string input, temp;
		vector<string> s;
		getline(cin, input);
		for (int i = 0; i < input.length(); i++) {
			int start = i;
			while (i < input.length() && input[i] != ' ') {
				i++;
			}
			for (int j = i - 1; j >= start; j--) {
				cout << input[j];
			}
			if (i != input.length())
				cout << ' ';
			else
				cout << '\n';
		}
	}
}

 

'Problem Solving > ICPC' 카테고리의 다른 글

[ICPC][BOJ] 13335 - Trucks  (0) 2019.09.23
[ICPC][BOJ] 8912 - Sales  (0) 2019.09.23
[ACM-ICPC][BOJ] 8896 - Rock Paper Scissors  (0) 2019.09.04
[ACM-ICPC][BOJ] 10251 - Driving License  (0) 2019.08.27
[ACM-ICPC][BOJ] 9019 - DSLR  (0) 2019.08.16

+ Recent posts