Sicily 数字反转

【题意】

输入一个数字,把它反过来输出。

 1 #include<iostream>
 2 using namespace std;
 3 int main()
 4 {
 5     int n;
 6     cin>>n;
 7     int n2 = n;
 8     n = n > 0 ? n : -n;
 9     int ans=0;
10     while(n!=0)
11     {
12                ans = n%10 +  ans * 10;
13                n /= 10;
14     }
15     if(n2>0)
16     cout<<ans<<endl;
17     else
18     cout<<-ans<<endl;
19 }                                 
posted @ 2012-07-15 00:18  mrlaker  阅读(211)  评论(0编辑  收藏  举报