迅雷校招-整數翻轉
阿新 • • 發佈:2018-11-09
輸入一個有符號整數,輸出該整數的反轉值。
輸入描述:
一個整數
輸出描述:
一個整數
輸入例子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; }