• 1019 General Palindromic Number


    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.

    Although palindromic numbers are most often considered in the decimal system, the concept of palindromicity can be applied to the natural numbers in any numeral system. Consider a number N>0 in base b≥2, where it is written in standard notation with k+1 digits ai​ as ∑i=0k​(ai​bi). Here, as usual, 0≤ai​

    Given any positive decimal integer N and a base b, you are supposed to tell if N is a palindromic number in base b.

    Input Specification:

    Each input file contains one test case. Each case consists of two positive numbers N and b, where 0

    Output Specification:

    For each test case, first print in one line Yes if N is a palindromic number in base b, or No if not. Then in the next line, print N as the number in base b in the form "ak​ ak−1​ ... a0​". Notice that there must be no extra space at the end of output.


    Sample Input 1:

    27 2
    

    Sample Output 1:

    1. Yes
    2. 1 1 0 1 1

    Sample Input 2:

    121 5
    

    Sample Output 2:

    1. No
    2. 4 4 1

    题目大意

    给你一个正整数,将其转换为op进制,并判断其转换为op进制后,是否是回文数


    思路

    倒序取余,注意单个0的输出


    C/C++ 

    1. #include
    2. using namespace std;
    3. int main()
    4. {
    5. int nums[101],len=-1,N,op;
    6. cin >> N >> op;
    7. do{
    8. nums[++len] = N%op;
    9. N/=op;
    10. } while (N);
    11. for(int z=0;z<=len;z++){
    12. if(nums[z]!=nums[len-z]) {
    13. cout << "No" << endl;
    14. break;
    15. }
    16. if(z==len) puts("Yes");
    17. }
    18. cout << nums[len];
    19. for(int z=len-1;z>=0;z--) cout << " " << nums[z];
    20. return 0;
    21. }

  • 相关阅读:
    善网ESG周报(第二期)
    [Python图像处理] 基于图像均值消除随机噪声
    Redies(四) session共享的优化
    循环赛-(单循环)
    力扣刷题-删除链表中的重复节点
    SpringBoot篇---第四篇
    [Jdk版本不一致问题 ]终端查看jdk版本不一致
    Java中HashSet类简介说明
    设计模式——装饰器模式(Decorator Pattern)+ Spring相关源码
    c++怎么传递函数
  • 原文地址:https://blog.csdn.net/daybreak_alonely/article/details/127684912