1019 General Palindromic Number (20分)
A number that will be the same when it is written forwards or backwards is known as a Palindromic Number. For example, 1234321 is a palindromic number. All single digit numbers are palindromic numbers.
Sample Input 1:
27 2
Sample Output 1:
Yes
1 1 0 1 1
Sample Input 2:
121 5
Sample Output 2:
No
4 4 1
题目大意
输出n的b进制数,并判断是否是回文数。
刚读题看了两遍,好多单词不认识,,呜呜。但是看了一遍样例,秒懂。不影响做题。
求n进制模板do{}while()
- decimal system 十进制
- Palindromic Number 回文数
- standard notation 标准计数法
#include <iostream>
using namespace std;
int main(){
int n,b,num=0;
cin >> n >> b;
int array[32]={0};
do{
array[num++]=n%b;
n/=b;
}while (n!=0);
int flag=1;
for(int i=0;i<=num/2;i++){
if(array[i]!=array[num-1-i])
{flag=0;
break;
}
}
if(flag==0){
cout << "No" <<endl;
}else cout << "Yes" << endl;
for (int i=num-1;i>=0;i--){
if(i!=num-1)cout << " ";
cout << array[i] ;
}
return 0;
}