RainSpark @ 2022-06-22 10:46:53
#include<iostream>
#include<cstdio>
#include<cstring>
#define ull unsigned long long
#define ll long long
#define N 1005
using namespace std;
int n,ans;
int a[N],b[N];
string s;
int main(){
cin>>n>>s;
for(int i=s.size()-1;i>=0;i--){
if(n==16 && s[i]>='A' && s[i]<='F'){
a[s.size()-i]=s[i]-'A'+10;
}else{
a[s.size()-i]=s[i]-'0';
}
}
int len=s.size(),mlen;
for(ans=1;ans<=30;ans++){
mlen=len;
for(int i=1;i<=len;i++){
b[i]+=a[i]+a[len-i+1];
if(b[i]>=n){
b[i]-=n;
b[i+1]++;
if(i==1){
mlen++;
}
}
}
len=mlen;
bool isnum=1;
for(int i=1;i<=len;i++)
if(b[i]!=b[len-i+1]){
isnum=0;
break;
}
if(isnum==1){
cout<<"STEP="<<ans<<endl;
return 0;
}
for(int i=1;i<=len;i++)
a[i]=b[i];
memset(b,0,sizeof b);
}
cout<<"Impossible!"<<endl;
return 0;
}
by RainSpark @ 2022-06-22 10:51:35
4号点:
样例输入:
2
101111
样例输出:
Impossible!
WA程序输出:
STEP=3
程序中处理的错误回文串(STEP=3):
1110111
by Super_Supper @ 2022-07-09 10:59:36
@takeoff37808
判断最后一位进位错了,应为:
if (i == n) {
mlen++;
}
by RainSpark @ 2022-07-09 11:08:58
@sb_yyds
by Super_Supper @ 2022-07-09 11:19:22
@takeoff37808 ?我 AC 了
by Super_Supper @ 2022-07-09 11:19:55
额,说错了,是 i == len
by RainSpark @ 2022-07-09 11:28:30
@sb_yyds 懂了,已经 AC 了,谢谢!