求救,不知道为什么错了
查看原帖
求救,不知道为什么错了
399062
星宿未泯楼主2021/10/11 16:20
#include<iostream>
#include<cstring>
using namespace std;
int l,n;
char m[1000],f[1000];
void gjj()
{
	int lm=l+1;
	for(int i=0;i<l;i++)
		f[l-i-1]=m[i];
	for(int i=0;i<lm;i++)
	{
		m[i]+=f[i];
		m[i+1]/=n;
		m[i]%=n;
	}
	while(m[lm]=='0'&&lm>0)
		lm--;
}
bool hw()
{
	for(int i=0;i<l;i++)
	{
		if(m[i]!=m[l-i-1])
			return false;
	}
	return true;
}
int main()
{
	//freopen("P1999.in","r",stdin);
	//freopen("P1999.out","w",stdout);
	int t=0;
	cin>>n>>m;
	l=strlen(m);
	for(int i=0;i<l;i++)
	{
		if(m[i]>='0'&&m[i]<='9')
			m[i]-='0';
		else
			m[i]=m[i]-'A'+10;
	}
	while(!hw())
	{
		t++;
		if(t>30)
		{
			cout<<"Impossible";
			return 0;
		}
		gjj();
	}
	cout<<"STEP="<<t;
	//fclose(stdin);
	//fclose(stdout);
	return 0;
}
2021/10/11 16:20
加载中...