迅雷校招-整数翻转

输入一个有符号整数,输出该整数的反转值。

输入描述:

一个整数

输出描述:

一个整数

输入例子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;
}
扫描二维码关注公众号,回复: 3996314 查看本文章

猜你喜欢

转载自blog.csdn.net/salmonwilliam/article/details/82907801