【单词翻转】
【目录】
目录
【题目描述】
小明同学写单词的时候喜欢反着写,比如hello他会写成olleh。给出小明同学写的一个句子,请你将所有的单词复原。
【输入格式】
一行一个字符串表示句子,单词之间以空格分隔。
【输出格式】
每个单词一行
【输入样例】
输入 #1
olleh dlrow
【输出样例】
hello
world
【说明/提示】
句子长度不超过100,仅包含小写字母和空格,不存在多余的空格。
【代码】
#include <bits/stdc++.h>
using namespace std;
int main(){
char a[100000];
gets(a);
int x=0;
int lenlong=strlen(a);
a[lenlong]=' ';
for(int i=0; i<=lenlong; i++){
if(a[i]==' '){
for(int j = i-1;j>=i-x;j--){
cout << a[j];
}
if(i!=lenlong){
cout << endl;
}
x=0;
}
else{
x++;
}
}
return 0;
}