求助

P1015 [NOIP1999 普及组] 回文数

zhizhi_c @ 2022-08-29 23:25:51

打扰一下,有哪位大佬能找出bug吗?

#include<cstdio>
using namespace std;
typedef unsigned long long ll;
ll reverse(ll n){
    ll num=0;
    for(;n>0;n/=10) num=num*10+n%10;
    return num;
}

bool check(ll n){
    return n==reverse(n);
}

ll ans(int m){
    ll num=0;
    for(char ch;(ch=getchar())>='0' && ch<m+'0';) 
        num=num*m+(ch-'0');
    return num;
}

int main(){
    int n,i;
    ll m;
    scanf("%d\n",&n);
    m=ans(n);
    for(i=1;i<=30;i++){
        m+=reverse(m);
        if(check(m)){
            printf("STEP=%d",i);
            return 0;
        }
    }
    printf("Impossible!");
    return 0;
}

by CreutzWilknare @ 2022-08-29 23:27:56

不会。


by AfterFullStop @ 2022-08-30 07:59:25

@zhizhi_c

输入都不对了,输入有两个

进制你没考虑啊


by SamHJD @ 2022-08-30 08:00:32

要高精度吧


|