样例过了,爆零了,不懂110反过来不是11嘛Help

P1015 [NOIP1999 普及组] 回文数

CKAO @ 2022-03-29 21:59:18

#include<iostream>
#include<string>
#include<vector>
using namespace std;
typedef long long  LL;
LL qjs(string s,int b)
{
    LL res=0;
    for (auto c: s)
        res=res*b+c-'0';
    return res;
}
LL inverse(int x)
{
    LL res=0;
    while (x)
    {
        res=res*10+x%10;
        x/=10;
    }
    return res;
}
bool check(LL x)
{
    vector<int> mv;
    while (x)
    {
        mv.push_back(x%10);
        x/=10;
    }
    for (int i=0;i<mv.size()/2;i++)
        if (mv[i]!=mv[mv.size()-i-1])
            return false;
    return true;
}
int main()
{
    int n;
    string s;
    cin>>n>>s;
    LL res=qjs(s,n);
    for (int i=1;i<=30;i++)
    {
        res=res+inverse(res);
        if (check(res))
        {
            printf ("STEP=%d",i);
            return 0;
        }
    }
    printf ("Impossible!");
    return 0;
}

|