当前位置:网站首页>Degree of second offence
Degree of second offence
2022-04-21 23:53:00 【Hua Weiyun】
Programming requirements
In the editor on the right Begin-End Supplementary code between , Calculate the whole number ( Not more than 100 position , The data is provided by the platform ) Make two and return . Specifically “ The degree of a second offense ” The definition is as follows :
This number contains 2 The ratio of the number of bits to the number of bits ;
If the integer is negative , The degree increases 0.5 times ;
If the integer is even , Is to add 1 times .
Tips : For the requirements of this customs, the calculation shall not exceed 100 An integer , Obviously, you can't use int type , But you can treat a string of numbers as a string , Use a character array to receive input integers .
for example : Numbers -56782223456 It's a 11 digit , Among them is 3 individual 2, It's a negative number , And even , Then its offense degree is :3/11×1.5×2, about 0.818182.
Test examples
Input :-13142223336
Output :0.818182
i=input()
if i[0] == "-":
b = i.count("2")/len(i[1:])
b*=1.5
else:
b = i.count("2")/len(i)
if int(i[-1])%2==0:
b*=2
print("%.6f"%b)
版权声明
本文为[Hua Weiyun]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204212352454202.html
边栏推荐
猜你喜欢

Application of different R & D cooperation modes in cloud efficiency

Man machine verification reCAPTCHA V3 complete instructions

7.6 线程属性

7.5 线程等待终止

Click, walk and move of characters in 3D sandbox game

6. Protocol hierarchy and service model (key)

Click the imported file or click the component to enter the corresponding component page for editing

数据库连接池和Druid的使用

JDBC method parameter details drivermanager, statement, connection, resultset, Preparedstatement

《数字电子技术基础》3.3 CMOS门电路(下)
随机推荐
Why can't the case in switch be broken
LeetCode_ 70 climb stairs
The difference between IAAs, PAAS and SaaS
"Yushu technology" completed hundreds of millions of yuan of Series B financing and accelerated the large-scale commercial landing of quadruped robots
6、協議層次化和服務模型(重點)
Cvpr2022 oral | contribution imbalance in multimodal learning
【网络协议】DHCP和PXE
7.5 线程等待终止
1143 longest common subsequence
【Leetcode-每日一题】山羊拉丁文
《数字电子技术基础》3.3 CMOS门电路(下)
7.9 thread mutex
已有千人收藏,一起“干完”这份300页1000道面试题
基于apache集合工具包的并集、交集、差集工具类
Three special data types of redis -- hyperloglog cardinality statistics
Gartner发布新兴技术研究:深入洞悉元宇宙
C Mandelbrot and Julia fractal image generation program updated to version 2010-9-14, supporting multi-threaded computing and multi-core processor
L2-016 wish all lovers in the world are brothers and sisters who have been separated for many years (25 points)
Application of different R & D cooperation modes in cloud efficiency
C language topic 1: three digits that can be composed of 1,2,3,4