码迷,mamicode.com
首页 > 其他好文 > 详细

ecnu 2851 Easy

时间:2018-05-27 18:35:20      阅读:173      评论:0      收藏:0      [点我收藏+]

标签:lse   col   std   int   turn   namespace   als   IV   color   

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

long long p[20]={1,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000,10000000000,100000000000,1000000000000};

bool judge(long long x){
    int l=(int)(log10(x)+1);
    for(int i=1;i<=l/2;i++){
        if((x%p[i])/p[i-1]!=(x%p[l-i+1])/p[l-i])return false;
    }
    return true;
}

long long reverse(long long x){
    int l=(int)(log10(x)+1);
    long long res=0;
    int u;
    for(int i=0;i<l;i++){
        u=x%10;
        x/=10;
        res+=u*p[l-i-1];
    }
    return res;
}

int main(){
    long long n;
    scanf("%lld",&n);
    int cnt=0;
    do{
        cnt+=1;
        n=n+reverse(n);
        if(judge(n)){
            printf("%d %lld",cnt,n);
            break;
        }
    }while(1);
}

 

ecnu 2851 Easy

标签:lse   col   std   int   turn   namespace   als   IV   color   

原文地址:https://www.cnblogs.com/TAMING/p/9096796.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!