日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程语言 > python >内容正文

python

python大于小于1023python大于小于_PythonPAT 1023 Have Fun with Numbers

發(fā)布時(shí)間:2023/12/18 python 48 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python大于小于1023python大于小于_PythonPAT 1023 Have Fun with Numbers 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

題目

Notice that the number 123456789 is a 9-digit number consisting exactly the numbers from 1 to 9, with no duplication. Double it we will obtain 246913578, which happens to be another 9-digit number consisting exactly the numbers from 1 to 9, only in a different permutation. Check to see the result if we double it again!

Now you are suppose to check if there are more numbers with this property. That is, double a given number with k digits, you are to tell if the resulting number consists of only a permutation of the digits in the original number.

Input Specification:

Each input contains one test case. Each case contains one positive integer with no more than 20 digits.

Output Specification:

For each test case, first print in a line “Yes” if doubling the input number gives a number that consists of only a permutation of the digits in the original number, or “No” if not. Then in the next line, print the doubled number.

Sample Input:

11234567899

Sample Output:

1

2Yes

2469135798

題解

思路

建立一個(gè)哈希表,存放每個(gè)字符出現(xiàn)的次數(shù)

將原數(shù)乘以2后,和哈希表每個(gè)字符出現(xiàn)的次數(shù)作對(duì)比

完事兒嗷

數(shù)據(jù)結(jié)構(gòu)

_dict 是一個(gè)哈希表,對(duì)每個(gè)鍵默認(rèn)值是0

鍵是0到9的字符

值是它出現(xiàn)的次數(shù)

算法

對(duì)作為字符串的原數(shù),按照每一個(gè)字符出現(xiàn)的次數(shù)添加到哈希表

將原數(shù)乘以2,對(duì)每一個(gè)出現(xiàn)的字符,哈希表相應(yīng)減一

如果哈希表不是每一項(xiàng)都為0,那么就說(shuō)明是No

代碼

因?yàn)槭褂肞ython能AC,因此只放了Python的代碼。

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17from collections import defaultdict

_dict = defaultdict(int)

a = input()

for i in a:

_dict[i] += 1

a = str(int(a) * 2)

for i in a:

_dict[i] -= 1

for i in "0123456789":

if _dict[i] != 0:

print("No")

break

else:

print("Yes")

print(a)

創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來(lái)咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)

總結(jié)

以上是生活随笔為你收集整理的python大于小于1023python大于小于_PythonPAT 1023 Have Fun with Numbers的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。