当前位置:网站首页>1019 general palindromic number (20 points)
1019 general palindromic number (20 points)
2022-06-30 14:55:00 【Xue Dongjing】
1019 General Palindromic Number (20 branch )
The question
Give me two numbers N and b, seek N stay b Base represents the result and determines whether the result is a palindrome digit .( The first and last numbers are the same , The second and penultimate numbers are the same …)
Ideas
Hexadecimal conversion , use N Yes b Quotient and remainder N stay b The result in base , Then judge whether the result is palindrome . Be careful 0 In all bases it is 0, It's palindrome number .
Code
#include<stdio.h>
void function(int N,int b)
{
if(N==0){
printf("Yes\n0");
}else{
int x[1000],count=0,m;
int flag=0;
while(N){
x[count++]=N%b;
N/=b;
}
m=count/2+1;
for(int i=0;i<m;i++){
if(x[i]!=x[count-1-i]){
flag=1;
break;
}
}
if(flag){
printf("No\n");
}else{
printf("Yes\n");
}
for(int i=count-1;i>=0;i--){
if(i!=count-1){
printf(" ");
}
printf("%d",x[i]);
}
}
}
int main()
{
int N,b;
scanf("%d%d",&N,&b);
function(N,b);
return 0;
}
边栏推荐
- V3 02——What‘s new in Chrome extensions
- Matlab finds prime numbers within 100
- Sorting by character frequency
- Matlab function for limit, definite integral, first-order derivative, second-order derivative (classic examples)
- Determine the number of digits of an integer in MATLAB (one line of code)
- Binary rotation array (2)
- Add attributes to multimode
- JS time conversion standard format, timestamp conversion standard format
- ThinkPHP show method parameter controllable command execution
- Location of dichotomy
猜你喜欢

V3 03_ Getting started
![[extensive reading of papers] multimodal attribute extraction](/img/ec/546c107ac0d31deded7ca94fdf0e2d.jpg)
[extensive reading of papers] multimodal attribute extraction

The first dark spring cup dnuictf

CCF call auction (full mark code + problem solving ideas + skill summary) 201412 - 3

CCF Z-scan (full mark code + problem solving ideas) 201412-2

Querywrapper in mybaits plus

Computer screenshot how to cut the mouse in

CCF sequence segmentation (Full Score code + problem solving idea) 201509 -1

DiceCTF - knock-knock

PS dynamic drawing
随机推荐
Average and maximum values of MATLAB matrix
Searching for single element in dichotomy
PS dynamic drawing
One dimensional and two dimensional array addresses
Determine the number of digits of an integer in MATLAB (one line of code)
1131: genetic correlation
分布式--OpenResty+lua+Redis
[extensive reading of papers] sentimental analysis of online reviews with a hierarchical attention network
ThinkPHP v3.2 comment annotation injection write shell
Matlab judges the number of same purchases
Steps for commissioning of vertical machining center
Win10 one click Reset win10 to solve all system bugs without deleting any files and Applications
高精度CNC加工中心为什么会出现误差?这4个原因你要注意!
1136: password translation
1132: stone scissors cloth
1025 pat ranking (25 points)
Finding the median of two arrays by dichotomy
CCF date calculation (Full Score code + skill summary) February 2, 2015
V3_ Chrome extended Chinese translation document V3 directory
Finding the root of an integer by dichotomy