Input Specification:
Each input file contains one test case. Each case consists of two non-negative numbers N and b, where 0 <= N <= 109 is the decimal number and 2 <= b <= 109 is the base. The numbers are separated by a space.
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:
Yes
1 1 0 1 1
Sample Input 2:
121 5
Sample Output 2:
No
4 4 1
#include<stdio.h>
int main(){
long long n, b;
int a[1000];
scanf("%Ld%Ld\n", &n,&b);
int index = 0;
while(n != 0){
a[index++] = n%b;
n /= b;
}
int i = 0;
int j = index - 1;
int flag = 0;
while(i<j){
if(a[i] != a[j]){
flag = 1;
break;
}
i++;
j--;
}
if(flag)
printf("No\n");
else
printf("Yes\n");
for(i =index-1; i> 0; i--){
printf("%d ", a[i]);
}
printf("%d\n", a[0]);
return 0;
}
分享到:
相关推荐
原创:PAT 1019 General Palindromic Number (20 分)A number that will be the same when
PAT甲级 1024 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...
在计算机科学和信息学中,回文数(Palindromic Number)是一种数字,它从左向右念和从右向左念都一样。例如,12321是一个典型的回文数。给定一个进制B(2<=B<=20,十进制表示),输出所有的大于等于1小于等于300(十...
Palindromic Substring 20.Valid Parentheses 26.Remove Duplicates from Sorted Array 53.Maximum Subarray 70.Climbing Stairs 121.Best Time to Buy and Sell Stock 122.Best Time to Buy and Sell Stock II 123....
Palindromic Substring 7. Reverse Integer 9. Palindrome Number 11. Container With Most Water 12. Integer to Roman 13. Roman to Integer 14. Longest Common Prefix 15. 3Sum 20. Valid Parentheses 21. Merge...
zoj 3661 Palindromic Substring.md
Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000. Java AC 版本
Palindromic Substring (Manacher算法待完成) 6.ZigZag Conversion 7.Reverse Integer 8.String to Integer (atoi) 9.Palindrome Number 10.Regular Expression Matching 11.Container With Most Water 12.Integer ...
Palindromic Substring 006. ZigZag Conversion 007. Reverse Integer 008. String to Integer 009. Palindrome Number 010. Regular Expression Matching 011. Container With Most Water 012. Integer to Roman ...
Palindromic Substring 6.ZigZag Conversion 7.Reverse Integer 8.String To Integer 9.Palindrome Number 10.String To Integer 11.Container With Most Water 12.Integer To Roman 13.Roman To Integer 289 347 ...
Palindromic Substring 最长回文子串 6. ZigZag Conversion Z字型变换 7. Reverse Integer 整数反转 8. String to Integer (atoi) 字符串转换整数 (atoi) 9. Palindrome Number 回文数 10. Regular Expression ...
leetcode 516 8/13 - 8/18 周:leetcode#: 409. longestPalindrome 125. Valid Palindrome ...Palindromic Substring option: 516. Longest Palindromic Subsequence string replacement strStr II 链接:
回文数要确定是否需要取消费用,必须先确定是否需要取消费用。 Elnúmerodebe ser市长de 2dígitos。 Desarrollar unaaplicaciónque ingrese dosnúmerosy se cambien las posiciones pares del底漆númerocon el ...
leetcode信封 ...Palindromic Substring │ RansomNote.java //383. Ransom Note │ RussianDollEnvelope.java //354. Russian Doll Envelopes │ SlidingWindowMaximum.java //239. Sliding Window Maximum
c c语言_leetcode 0005_longest_palindromic_substring.zip
题目名称:**Palindromic Substrings** 题目描述: 给定一个字符串 `s`,你需要找到并输出该字符串中所有长度为偶数的回文子串的数量。 输入: 输入包含一行,为一个字符串 `s`(只包含小写字母,长度不超过 `10^5...
c语言入门 c语言_leetcode题解05-longest-palindromic-substring.c
js js_leetcode题解之5-longest-palindromic-substring.js
眼镜创建一个名为palindromeNumberGenerator的函数,该函数采用一个Number值。 检查数字是否为回文数,如果不是,则将值和取反的值相加,并检查总和是否为回文数,重复直到达到回文数值。 每次对这些值求和以获取新...
Palindromic Substring 最长回文子串,补符号,记忆 6. ZigZag Conversion 观察规律 7. Reverse Integer 翻转整数 8. String to Integer 解析字符串 9. Palindrome Number 回文数字 10. Regular Expression Matching...