wch666 @ 2023-11-14 21:04:16
#include<bits/stdc++.h>
using namespace std;
int n;
string s;
int a[105],b[105],c[105];
int lena,lenb;
bool pd()
{
int t=lenb/2;
for (int i=0; i<=t; i++)
if (c[i] != c[lenb-i])
return false;
return true;
}
void jia()
{
int x=0;
while(lenb < lena)
{
c[lenb]=a[lenb]+b[lenb]+x;
x=c[lenb]/n;
c[lenb]%=n;
lenb++;
}
if(x != 0)
c[lenb]=x;
else
lenb--;
}
int main()
{
cin>>n>>s;
lenb=0;
lena=s.size();
for(int i=0; i<lena; i++)
a[lena-1-i]=s[i]-'0';
for(int i=0; i<lena; i++)
b[i]=a[lena-1-i];
for(int tmp=1; tmp<=30; tmp++)
{
jia();
if(pd())
{
printf("STEP=%d",tmp);
return 0;
}
}
cout<<"Impossible!";
return 0;
}
by Shirley_ninefish @ 2023-11-14 21:32:54
@wch666 n可以等于16哦,所以可能会输入输出带字母
by Shirley_ninefish @ 2023-11-14 22:00:34
而且每次循环都要清空lenb,再更新a、b数组