A_HissingCreeper @ 2022-08-02 21:43:47
感觉写的没错结果连样例都过不了
#include<bits/stdc++.h>
using namespace std;
int jinz;
int ans;
string k;
string ss;
string gjd(string s1,string s2,int jz)
{
cin>>s1>>s2;
string s3;
int a[510],b[510],c[510];
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
memset(c,0,sizeof(c));
int len=max(s1.length(),s2.length());
for (int i=s1.length()-1,j=1;i>=0;i--,j++)
a[j]=s1[i]-'0';
for (int i=s2.length()-1,j=1;i>=0;i--,j++)
b[j]=s2[i]-'0';
for(int i=1;i<=len;i++)
{
c[i]+=a[i]+b[i];
c[i+1]=c[i]/jz;
c[i]%=jz;
}
if(c[len+1])
{
len++;
}
for(int i=len;i>=1;i--)
{
int point=0;
s3[point]=c[i]+'0';
point++;
}
return s3;
}
bool hw(string s)
{
int len=s.length();
for(int i=0;i<len;i++)
if(s[i]!=s[len-1-i])return 0;
return 1;
}
int main()
{
cin>>jinz>>k;
ss=k;
for(int i=1;i<=30;i++)
{
ans++;
string s=ss;
reverse(ss.begin(),ss.end());
ss=gjd(ss,s,jinz);
if(hw(ss))
{
cout<<"STEP="<<ans;
return 0;
}
}
cout<<"Impossible!";
return 0;
}
求各位大佬指明错误
by ZGC1111 @ 2022-08-14 20:50:19
你要考虑进制
by ZGC1111 @ 2022-08-14 21:00:21
@songzxzydy