输入一个有符号整数,输出该整数的反转值。
输入描述:
一个整数
输出描述:
一个整数
输入例子1:
123
输出例子1:
321
输入例子2:
-123
输出例子2:
-321
输入例子3:
200
输出例子3:
2
题目链接:https://www.nowcoder.com/test/question/14733e0bfa9b474ba7cbe0bb2e459731?pid=12398194&tid=19094229
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main()
{
int flag=0,x;
cin>>x;
if(x<0)
flag=1;
if(x==0)
cout<<0;
while(x)
{
if(flag)
{
cout<<"-";
flag=0;
}
if(x%10==0);
else
{
cout<<abs(x%10);
}
x=x/10;
}
return 0;
}