P1307 数字反转

P1307 数字反转

题目链接:https://www.luogu.org/problem/P1307

代码

#include <bits/stdc++.h>
using namespace std;

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    long long n,a,b=0;
    cin>>n;
    while(n%10==0){    //判断n后几位有零的情况;
        n = n/10;
        //cout<<n<<endl;
    }
    while(n!=0){
        a = n%10;
        b = b*10+a;    //把除去尾数为零的n从后往前存入b中;
        n = n/10;
        //cout<<a<<""<<b<<" "<<n<<" ";
    }
    cout<<b<<endl;
    return 0;
}
posted @ 2019-07-26 21:23  幽灵小一只  阅读(257)  评论(0编辑  收藏  举报