Nicrobot @ 2021-09-02 21:14:00
输入:
2
101
正确输出:
STEP=0
代码输出:
STEP=2
代码:
#include<bits/stdc++.h>
using namespace std;
int n,len;
char s[100001];
int a[100001],b[100001];
void solve(int step) {
if(step==31) {
puts("Impossible!");
return;
}
for(int i=1; i<=len; i++) {
b[i]=a[i]+a[len-i+1];
}
for(int i=1; i<=len; i++) {
a[i]=b[i];
}
for(int i=1; i<len; i++) {
if(a[i]>=n)a[i+1]+=a[i]/n,a[i]%=n;
}
if(a[len]>=n)a[len+1]=a[len]/n,a[len]%=n,len++;
bool ok=1;
for(int i=1; i<=len/2; i++)
if(a[i]!=a[len-i+1])ok=0;
if(ok)cout<<"STEP="<<step<<endl;
else solve(step+1);
}
int main() {
cin>>n>>s;
len=strlen(s);
for(int i=0; i<len; i++) {
if(s[i]>='0'&&s[i]<='9')a[len-i]=s[i]-'0';
else a[len-i]=s[i]-'A'+10;
}
solve(1);
return 0;
}
问题:刚开始没有判断是否已经是回文 (如果这样的数据不行自删)
by Nicrobot @ 2021-09-02 21:21:45
@huangzhikun @hong123 输出
STEP=2
@assassinRay
输出
0
by zhangshuhao123 @ 2021-09-05 16:48:12
...
by ZRHan @ 2022-06-28 18:17:56
感谢,输出impossible