欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

1019

程序员文章站 2022-05-30 13:17:50
...
#include<iostream>
#include<stack>
#include<string>
using namespace std;
void ChangeTo(stack<int> &S,int n,int b);
void Judge(int N[1000],int len);
int main()
{
	int n, b;
	cin >> n >> b;
	stack <int > S;
	int N[1000];
	ChangeTo(S,n,b);
	int len = 0;
	while (!S.empty())
	{
		N[len++] = S.top();
		S.pop();
	}
	Judge(N,len);
	system("pause");
	return 0;
}
void Judge(int N[1000],int len)
{
	int f,h;
	int flag = 1;
	f = 0;
	h = len - 1;
	while (f <= h)
	{
		if (N[f] == N[h])
		{
			f++;
			h--;
		}
		else
		{
			flag = 0;
			break;
		}
	}
	if (flag == 0)
		cout << "No" << endl;
	else
		cout << "Yes" << endl;
	for (int i = 0; i < len; i++)
	{
		if (i == 0)
			cout << N[i];
		else
			cout << ' ' << N[i];
	}
	cout << endl;
}
void ChangeTo(stack<int> &S,int n,int b)
{
	while (n)
	{
		S.push(n%b);
		n /= b;
	}
}