保龄

P1307 [NOIP2011 普及组] 数字反转

S0CRiA @ 2020-10-16 21:00:24

//P1307
#include <iostream>
using namespace std;

long long number_reverse(long long n){
    long long ans=0,t;
    while(n%10==0){
        n /= 10;
    }
    while(t){
        t = n % 10;
        n /= 10;
        ans += t;
        ans *= 10;
    }
    ans /= 100;
    return ans;
}

int main(){
    int n;
    cin >> n;
    cout << number_reverse(n);
    return 0;
}

by yyyyyyy @ 2020-10-16 21:05:34

while (t)$-->$while(n) ans /= 100$ --> $ans /= 10

by yyyyyyy @ 2020-10-16 21:06:33

第一个while其实可以不用


by S0CRiA @ 2020-10-16 21:11:36

@yyyyyyy

谢谢!


|