含義:輸入任意數(shù)值漓摩,輸出順序相反的數(shù)值讥邻。
E.G. 輸入874,輸出478
提示:除10取余可拿最后1位數(shù)懊蒸,除10向下取整可拿除最后1位數(shù)的其他數(shù)字(整體)。
#include <iostream>
using namespace std;
class Solution {
public:
? ? ? ?int revers(int x){
? ? ? ? ? ? ?int responsenumber = 0;
? ? ? ? ? ? ?if (x > INT32_MAX /10 ||? x < INT_MIN /10) return 0
? ? ? ? ? ? ?while(x!=0){
? ? ? ? ? ? ? ? ? ? ?responsenumber = rensponsenumber*10 + x%10;
? ? ? ? ? ? ? ? ? ? ?x = x/10;
? ? ? ? ? ? ? }
? ? ? ? ? ? ? return responsenumber;
? ? ? ?}
};
int main(){
? ? ?Solution solution;
? ? ?int number;
? ? ?cin>>number;
? ? ?cout<<solution.reverse(number)<<endl;
}