救救我

P1015 [NOIP1999 普及组] 回文数

Hanxiaoyang @ 2024-08-13 16:44:07

#include<bits/stdc++.h>

using namespace std;

int sum=0;

bool hui(string s){

    int zo = 0,you = s.size()-1;

    while(zo<you){

        if(s[zo]!=s[you]) return false;

        zo++;you--;

        }

    return true;

}

int zhuan1(char ss){

     if(ss>='A'&&ss<='Z') return ss-'A'+10;

     else return ss-'0';

}
char zhuan2(int sss){

    if(sss<10) return sss+'0';

    else return sss+'A'-10;

}
string gao(string s1,int c1){

    string a1,b1;

    for(int i = 0;i<s1.size();i++){

        a1[i] = s1[i];

        b1[i] = s1[s1.size()-1-i];

    }

    int c[1005] = {0},len = s1.size();

    for(int i = 0;i<s1.size();i++){

        c[i] += zhuan1(a1[i])+zhuan1(b1[i]);

        c[i+1] += c[i]/c1;

        c[i] %= c1;

    } 

    if(c[s1.size()]) len++;

    for(int i = 0;i<len;i++){

        s1[i] = zhuan2(c[i]);

    }

    return s1;

}

int main(){

    int a;

    string b;

    cin>>a>>b;

    cout<<gao(b,a);

    while(!hui(b)){

        gao(b,a);

        sum++;

        if(sum>30){

            break;

        }

    }

    if(sum<=30){

        cout<<"STEP="<<sum;

    }

    else{

        cout<<"Impossible!";

    }

    return 0;

}

by yhcorey @ 2024-08-13 16:56:10


#include<bits/stdc++.h>
using namespace std;
int a[150],b[150],c[150];
bool e(string m,int lb){
    for(int k=0;k<=lb/2;k++){
        if(m[k]!=m[lb-k-1]) return false;
    }
    return true;
}
int main(){
    string x;
    char y[150]="";
    int n;
    cin>>n>>x;
    int la=x.size();
    for(int i=0;i<la;i++){
        if(x[la-i-1]-'0'>=0&&x[la-i-1]-'0'<=9) a[i]=x[la-i-1]-'0';
        else a[i]=x[la-i-1]-55;
    }
    for(int i=0;i<30;i++){
        for(int j=0;j<la;j++){
            b[j]=a[la-j-1];
        }
        for(int j=0;j<la;j++){
            a[j]+=b[j];
            if(a[j]>=n){
                a[j+1]++;
                if(a[j+1]==1&&j==la-1) la++;
            }
            a[j]=a[j]%n;
        }
        for(int j=0;j<la;j++){
            if(a[j]<=9){
                char z=a[j]+'0';
                y[j]=z;
            }
            else{
                char z=a[j]+55;
                y[j]=z;
            }
        }
        if(e(y,la)){
            cout<<"STEP="<<i+1;
            return 0;
        }
    }
    cout<<"Impossible!";
    return 0;
}```

by Hanxiaoyang @ 2024-08-13 17:04:28

谢谢大佬


by tyc20140404 @ 2024-08-16 17:59:46

?好简单


|