0
Write a program that can reverse the words in a given sentence without breaking the order.
For example "Hello world" will return "olleH dlrow", NOT "dlrow olleH"
3 Respuestas
+ 13
#My try ☺️
#python (1 liner)
print(" ".join(str[::-1] for str in input().split(" ")))
0
#include <iostream>
#include <string>
using namespace std;
int main(){
string a[100];
int n = 0;
string s = "";
for (char c; (c = getchar()) != '\n';) {
if (c == ' ') {
a[n] = s;
n++;
s = "";
}
else {
s += c;
}
}
a[n] = s;
n++;
for (int i = 0; i < n; i++) {
reverse(a[i].begin(), a[i].end());
cout « a[i] « " ";
}
}