PAT 甲级 1019 General Palindromic Number
作者:互联网
PAT 甲级 1019 General Palindromic Number
水题,把数字转换成对应进制,从两头往中间找,看是否对齐
n==0是直接输出Yes和0
// 1019 General Palindromic Number.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//
#include <iostream>
using namespace std;
int main()
{
int n, b;
cin >> n >> b;
int arr[40], cnt= 0;
bool flag = false;
if (n == 0) flag = true;
while (n != 0) {
arr[cnt++] = n % b;
n /= b;
}
for (int i = 0; i < cnt / 2; i++) {
if (arr[i] != arr[cnt - 1 - i]) {
flag = true;
break;
}
}
if (flag) {
cout << "No\n";
}
else {
cout << "Yes\n";
}
for (int i = cnt - 1; i >= 0; i--) {
if (i != cnt - 1) cout << " ";
cout << arr[i];
}
return 0;
}
标签:cnt,PAT,cout,arr,Palindromic,int,Number,flag 来源: https://blog.csdn.net/weixin_43480561/article/details/117850479