题解 | #数字颠倒#
数字颠倒
http://www.nowcoder.com/practice/ae809795fca34687a48b172186e3dafe
#include<iostream> #include<string> using namespace std; int main() { int a; cin>>a; string res; res=to_string(a);//使用to_string(), 把整型数字转换成字符串 int len=res.size(); string rest;//逆序后的字符串 rest.resize(len); for(int i=0;i<len;i++)//手动逆序 { rest[len-i-1]=res[i];//注意这里是 len-i-1,不然会发生数组越界 } cout<<rest<<endl; return 0; }