Love丶FFC's Blog
给定一个 k+1 位的正整数 N,写成 ak⋯a1a0的形式,其中对所有 i 有 0≤ai<10 且 ak>0。N 被称为一个回文数,当且仅当对所有 i有 ai=ak−i。零也被定义为一个回文数。
非回文数也可以通过一系列操作变出回文数。首先将该数字逆转,再将逆转数与该数相加,如果和还不是一个回文数,就重复这个逆转再相加的操作,直到一个回文数出现。如果一个非回文数可以变出回文数,就称这个数为延迟的回文数。(定义翻译自 https://en.wikipedia.org/wiki/Palindromic_number )
给定任意一个正整数,本题要求你找到其变出的那个回文数。
输入在一行中给出一个不超过1000位的正整数。
对给定的整数,一行一行输出其变出回文数的过程。每行格式如下
A + B = C
其中 A
是原始的数字,B
是 A
的逆转数,C
是它们的和。A
从输入的整数开始。重复操作直到 C
在 10 步以内变成回文数,这时在一行中输出 C is a palindromic number.
;或者如果 10 步都没能得到回文数,最后就在一行中输出 Not found in 10 iterations.
。
97152
97152 + 25179 = 122331
122331 + 133221 = 255552
255552 is a palindromic number.
196
196 + 691 = 887
887 + 788 = 1675
1675 + 5761 = 7436
7436 + 6347 = 13783
13783 + 38731 = 52514
52514 + 41525 = 94039
94039 + 93049 = 187088
187088 + 880781 = 1067869
1067869 + 9687601 = 10755470
10755470 + 07455701 = 18211171
Not found in 10 iterations.
1.首先对特例情况进行判断
2.利用字符串拼接得到B
3.判断是否回文可以使用两边往中间逐位比较的方法,如165561,依次进行1==1、6==6、5==5的比较
Number = input() # 输入原始数字 Count = 0 # 操作的次数 A = Number Palindrome = True # 标记是否为回文数,默认为是 for i in range(len(A)): # 特例:输入的数就是回文数 if A[i] != A[len(A) - i - 1]: Palindrome = False break if Palindrome: print(A + " is a palindromic number.") else: while True: B = "" # 逆转数 for i in range(len(A) - 1, -1, -1): B += A[i] C = str(int(A) + int(B)) Count += 1 # 完成一次操作 print(A + " + " + B + " = " + C) # 输出运算结果 Palindrome = True # 每次都将标记重置 for i in range(len(C)): # 遍历C,从左边、右边同时逐位往中间判断 if C[i] != C[len(C) - i - 1]: # 两字符不相同 Palindrome = False break if Palindrome: # C是回文数 print(C + " is a palindromic number.") break else: # C不是回文数,继续操作 A = C if Count == 10: # 操作次数超过规定 print("Not found in 10 iterations.") break
cheap louis vuitton handbags
I just wanted to thank you for the fast service. maybe they look great. I received them a day earlier than expected. including the I will definitely continue to buy from this site. you ultimately choose I will recommend this site to my friends. Thanks!
cheap louis vuitton handbags https://www.bestlouisvuittonoutlet.com/
cheap jordans for sale
I just wanted to thank you for the fast service. or else they look great. I received them a day earlier than expected. for example I will definitely continue to buy from this site. anyway I will recommend this site to my friends. Thanks!
cheap jordans for sale https://www.cheaprealjordan.com/
cheap jordans
I just wanted to thank you for the fast service. or it may be they look great. I received them a day earlier than expected. such as the I will definitely continue to buy from this site. blue jays I will recommend this site to my friends. Thanks!
cheap jordans https://www.realjordansretro.com/
original louis vuittons outlet
I just wanted to thank you for the fast service. aka they look great. I received them a day earlier than expected. for example I will definitely continue to buy from this site. anyway I will recommend this site to my friends. Thanks!
original louis vuittons outlet https://www.cheapreallouisvuitton.com/
cheap louis vuitton online
I just wanted to thank you for the fast service. or maybe they look great. I received them a day earlier than expected. just like the I will definitely continue to buy from this site. in any event I will recommend this site to my friends. Thanks!
cheap louis vuitton online https://www.louisvuittonsoutletstore.com/
Gealpaste
Helping Carlos or others is for the sake of It is only a means to achieve this goal, Now is not the time for internal how long how long to allow for new blood pressure medicine to allow for new blood pressure medicine fighting, Marshal Rocherio, Our betrayal puts us at a great disadvantage, so temporary apparent weakness is not a sign of cowardice cheap cialis online
intuido
Ask your doctor to tell you about the specific harm that may be done to the fetus cheapest propecia uk
mYbBcH
Serious Use Alternative 1 enoxaparin, zanubrutinib priligy over the counter usa Patients should be evaluated for future anxiety and potential PTSD symptoms when they are initiated on new medications
Hgazmh
buy fenofibrate 200mg pills order fenofibrate 160mg for sale buy generic fenofibrate for sale
Wlzvuj
generic cialis canada viagra 100mg sale purchase sildenafil
Innqfx
order ketotifen generic ketotifen 1 mg without prescription imipramine 75mg for sale
Kudbyp
buy minoxidil generic buy ed pills best price buy generic ed pills over the counter
Ripycd
precose 50mg brand purchase fulvicin without prescription order fulvicin 250 mg without prescription