这一题挺简单的,读入输入数值之后直接从后面往回输出就好,不过问题在于读入的时候,不能用cin>>,它会忽略空格和换行:
这里用cin.get(),它可以读入空格和换行
#include<iostream>
#include<string>
//问题应该是cin不能读取空格,那应该如何读取一个字符串呢?
using namespace std;
int main(){
string a="";
char c;
string res="";
while((c=cin.get())!='\n'){//答案在这里
a+=c;
};
for(int i=a.size()-1;i>=0;--i){
res+=a[i];
}
cout<<res<<endl;
return 0;
}