This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
#include<vector> | |
#include<string> | |
#include <sstream> | |
#include <iterator> | |
using namespace std; | |
template<typename Out> | |
void split(const std::string &s, char delim, Out result) { | |
std::stringstream ss; | |
ss.str(s); | |
std::string item; | |
while (std::getline(ss, item, delim)) { | |
*(result++) = item; | |
} | |
} | |
void reverse(string &str){ | |
for (int i=0;i<str.length()/2;i++){ | |
char temp = str[i]; | |
str[i] = str[str.length()-1-i]; | |
str[str.length()-1-i] = temp; | |
} | |
} | |
std::vector<std::string> split(const std::string &s, char delim) { | |
std::vector<std::string> elems; | |
split(s, delim, std::back_inserter(elems)); | |
return elems; | |
} | |
int main(void) | |
{ | |
int N; | |
cin >> N; | |
vector<string> vec; | |
cin.ignore(); | |
for (int i=0;i<N;i++) | |
{ | |
string str = ""; | |
getline(cin,str); | |
vec = split(str,' '); | |
for (int j=0;j<vec.size();j++) | |
{ | |
reverse(vec[j]); | |
if (j == vec.size()-1) | |
cout << vec[j] << endl; | |
else | |
cout << vec[j] << " "; | |
} | |
vec.clear(); | |
} | |
} |
댓글
댓글 쓰기