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 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 ...
USACO题目Palindromic Squares(回文平方数)及代码解析
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
眼镜创建一个名为palindromeNumberGenerator的函数,该函数采用一个Number值。 检查数字是否为回文数,如果不是,则将值和取反的值相加,并检查总和是否为回文数,重复直到达到回文数值。 每次对这些值求和以获取新...
Palindromic Substring 最长回文子串,补符号,记忆 6. ZigZag Conversion 观察规律 7. Reverse Integer 翻转整数 8. String to Integer 解析字符串 9. Palindrome Number 回文数字 10. Regular Expression Matching...
Palindromic Substring - 字数组余数:523. Continuous Subarray Sum - 无重复字符的最长子串:3. Longest Substring Without Repeating Characters - 最小跳跃步数问题 - 动态规划 + 循环策略优化:45. Jump Game ...
Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000. Example: Input: "babad" Output: "bab" Note: "aba" is also a valid answer. ...
Palindromic Substring: Learning "Manacher" algorithm. tips:substr(start_position,lens) 6. ZigZag Conversion: Find the Regulation. 11. Container With Most Water 问题简述:给出一个list a,找到一组i,j使得...
Palindromic Substring 这里使用menecher方法,就是动态规划,首先在原先的字符串之间插入'#, 这样可以统一处理奇数串和偶数串, 使用两个变量纪录状态, far_pos表示最长回文字符串的最大边界距离,ci表示最长回文...