QQ登录

只需一步,快速开始

One fragment of a given integer N can be selected and its digits reversed (re...

[复制链接]
浪漫的乌云 发表于 2022-3-21 06:52:21 [显示全部楼层] 回帖奖励 倒序浏览 阅读模式 0 3034
One fragment of a given integer N can be selected and its digits reversed (replaced with a right to left version of themselves). What is the maximum number that can be obtained this way from integer N


Answer Expert Verified

Integers are numbers without decimal points. The number could be positive, negative or zero


How to determine the maximum number from the integer

The maximum number from integer N can be determined using the following program written in Python, where comments are used to explain each line


#This prompts the user for input

num = input("Number: ")

#This iterates from 0 to 9

kount = [0 for x in range(10)]

# This iterates through the input, and updates the kount variable

for i in range(len(num)):

   kount[int(num)] = kount[int(num)] + 1


# This next two lines initialize the greatest number

greatestNum = 0

multiplier = 1


# This iterates through the kount array

for i in range(10):

   #The following is repeated while the current element is greater than 0

while kount > 0:

    #This generates the greatest number

greatestNum = greatestNum + ( i * multiplier )

kount = kount - 1

multiplier = multiplier * 10

#This prints the greatest number

print(greatestNum)


Read more about similar programs at:

brainly.com/question/15683939

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

官方微博
官方微博
模板大全
模板大全
意见
反馈