9093_단어뒤집기(C++)

#include <iostream>
#include<stack>
#include<string>
using namespace std;

int main() {
	stack<char> mine;
	int T;
	string command;
	cin >> T;
	cin.ignore();
	for (int i = 0; i < T; i++) {
		getline(cin, command); 
		command += '\n';
		for (int j = 0; j < command.length(); j++) {
			if (command[j] == ' ' || command[j] == '\n') {;
				while (!mine.empty()) {
					cout << mine.top();
					mine.pop();
				}cout << command[j];
			}
			else {
				mine.push(command[j]);
			}
		}
	}
}

스택 설명 참고:
https://velog.io/@kimeunseo58/%EC%8A%A4%ED%83%9D
스택 소스코드:
https://velog.io/@kimeunseo58/10828%EC%8A%A4%ED%83%9DC

좋은 웹페이지 즐겨찾기