mle怎么办

P1015 [NOIP1999 普及组] 回文数

wjh123bc @ 2024-09-22 08:54:05

#include <bits/stdc++.h>
using namespace std;
const int N=0x3f3f3f3f;
string s;
int a[200005];
struct bigint
{
    string s;
    int r;
    friend bigint operator + (const bigint a,const bigint b)
    {
        string s1=a.s,s2=b.s;
        reverse(s1.begin(),s1.end());
        reverse(s2.begin(),s2.end());
        int shu1[10050],shu2[10050],ans[10050];
        memset(shu1,0,sizeof(shu1));
        memset(shu2,0,sizeof(shu2));
        memset(ans,0,sizeof(ans));
        int len1=s1.size(),len2=s2.size();
        for(int i=0;i<len1;i++) shu1[i]=int(s1[i]-48);
        for(int i=0;i<len2;i++) shu2[i]=int(s2[i]-48);
        int len=max(len1,len2);
        for(int i=0;i<len;i++)
        {
            ans[i]+=shu1[i]+shu2[i];
            if(ans[i]>=10)
            {
                ans[i+1]++;
                ans[i]=ans[i]%10;
            }
        }
        if(ans[len]!=0) len++;
        while(ans[len-1]==0&&len>1) len--;
        bigint lin;
        lin.s="";
        for(int i=len-1;i>=0;i--) lin.s+=char(ans[i]+48);
        return lin;
    }
};
int main() 
{
    bigint m,k;
    int n,ans=0;
    cin>>n>>m.s;
    for(int i=1;i<=30;i++)
    {
        ans++;
        k.s=m.s;
        reverse(k.s.begin(),k.s.end());
        m.s=(m.s+k.s);
        int len=m.s.size();
        bool flag=true;
        for(int j=0;j<len;j++)
        {
            if(m.s[j]!=m.s[len-j])
            {
                flag=false;
                break;
            }
        }
        if(flag==true)
        {
            cout<<"STEP="<<ans;
            return 0;
        }
    }
    return 0;
}

by linmingjia @ 2024-09-22 16:23:19

#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<cstdio>
const int N=10000;
using namespace std;
int m,sum=0;
struct bigint
{
    string num;
    friend bigint operator +(const bigint a,const bigint b)
    {
        int yi[N],er[N],he[N];
        memset(yi,0,sizeof(yi));
        memset(er,0,sizeof(er));
        memset(he,0,sizeof(he));
        int len1=a.num.size();
        int len2=b.num.size();
        for(int i=0;i<len1;i++)
        {
            if(a.num[len1-i-1]>='A') yi[i]=a.num[len1-i-1]-55;
            else if(a.num[len1-i-1]<='9') yi[i]=a.num[len1-i-1]-48;
        }
        for(int i=0;i<len2;i++)
        {
            if(b.num[len2-i-1]>='A') er[i]=b.num[len2-i-1]-55;
            else if(b.num[len2-i-1]<='9') er[i]=b.num[len2-i-1]-48;
        }
        int len=max(len1,len2);
        for(int i=0;i<len;i++) he[i]=yi[i]+er[i];
        for(int i=0;i<len;i++)
        {
            if(he[i]>=m)
            {
                he[i+1]+=he[i]/m;
                he[i]=he[i]%m;
            }
        }
        if(he[len]!=0) len++;
        bigint ans;
        ans.num="";
        for(int i=len-1;i>=0;i--)
        {
            if(he[i]>=10) ans.num=ans.num+char(he[i]+55);
            else ans.num=ans.num+char(he[i]+48);
        }
        return ans; 
    }
};
int main()
{
    bigint s;
    cin>>m>>s.num;
    while(sum<=30)
    {
        bigint zheng;
        zheng.num=s.num;
        reverse(zheng.num.begin(),zheng.num.end());
        if(zheng.num==s.num)
        {
            cout<<"STEP="<<sum;
            return 0;
        }
        s=s+zheng;
        sum++;
    }
    cout<<"Impossible!";
    return 0;
}

|