求求求

P1015 [NOIP1999 普及组] 回文数

scopin @ 2024-03-13 20:35:03

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

int n,m,ans[10086],lenm,anns=0;

void start(){
    cin >> n >> m;
    int x=m;
    while(x){
        ans[++lenm]=x%10;
        x/=10;
    }
}
bool IfIshuiwenshu(){
    bool ww=1;
    for(int i=1;i<=lenm/2;i++){
        if(ans[i]==ans[lenm-i+1]) ww=0;
        else ww=1;
    }
    return ww;
}

void show(){
    for(int i=1;i<=lenm;i++) cout << ans[i] <<endl;
}

void solve(){
    while(IfIshuiwenshu()){
//      int cnt=0;
        for(int i=1;i<=lenm;i++){
//          cout << ans[i] << "=============" <<endl;
            ans[i]+=ans[i];
            if(ans[i]>=n){
                ans[i+1]+=(ans[i]/n);
                ans[i]=ans[i]%n;
//              cout << ans[i] <<endl;
            }
//          cnt=i;
            if(ans[i+1]) lenm++;
        }
//      show()
        anns++;
    }
}

int main(){
    //freopen("P1015.txt","r",stdin);
    start();
    solve();

    cout << anns;
} 

|