#include <iostream>
#include <string>
using namespace std;
int main(){
string primary_words, rev_words;
int cnt;
while(getline(cin, primary_words)){
int l = primary_words.size();cnt = 0;
for(int i = 0; i < l; i++){
cnt++;
if(primary_words[i] == ' '){
int m = 0;
for(int k = cnt-2; k >= 0; k--){
rev_words.push_back(primary_words[i-1]);i--;m++;
}i += m;
rev_words.push_back(' ');cnt = 0;
}
if(i == l-1){
int m = 0;
for(int k = cnt-1; k >= 0; k--){
rev_words.push_back(primary_words[i]);i--;m++;
}i += m;
}
}
cout << rev_words << endl;
rev_words.clear();
}
return 0;
}
#include <string>
using namespace std;
int main(){
string primary_words, rev_words;
int cnt;
while(getline(cin, primary_words)){
int l = primary_words.size();cnt = 0;
for(int i = 0; i < l; i++){
cnt++;
if(primary_words[i] == ' '){
int m = 0;
for(int k = cnt-2; k >= 0; k--){
rev_words.push_back(primary_words[i-1]);i--;m++;
}i += m;
rev_words.push_back(' ');cnt = 0;
}
if(i == l-1){
int m = 0;
for(int k = cnt-1; k >= 0; k--){
rev_words.push_back(primary_words[i]);i--;m++;
}i += m;
}
}
cout << rev_words << endl;
rev_words.clear();
}
return 0;
}
No comments:
Post a Comment