当前位置:网站首页>到底有多二(Lua)
到底有多二(Lua)
2022-07-07 15:38:00 【有趣就行】
题目
一个整数“犯二的程度”定义为该数字中包含2的个数与其位数的比值。如果这个数是负数,则程度增加0.5倍;如果还是个偶数,则再增加1倍。例如数字-13142223336是个11位数,其中有3个2,并且是负数,也是偶数,则它的犯二程度计算为:3/11×1.5×2×100%,约为81.82%。本题就请你计算一个给定整数到底有多二。
输入格式:
输入第一行给出一个不超过50位的整数N。
输出格式:
在一行中输出N犯二的程度,保留小数点后两位。
输入样例:
-13142223336
输出样例:
81.82%
代码
local n = io.read()
local ans= 0
for i = 1, #n do
if n:sub(i, i) == "2" then
ans = ans + 1
end
end
if n:sub(1, 1) == "-" then
ans = ans / (#n - 1) * 1.5
else
ans = ans / #n
end
if tonumber(n:sub(#n, #n)) % 2 == 0 then
ans = ans * 2
end
print(string.format("%.2f%%", ans * 100))
边栏推荐
- Sator launched Web3 game "satorspace" and launched hoobi
- 麒麟信安加入宁夏商用密码协会
- Rpcms method of obtaining articles under the specified classification
- MySQL implements the query of merging two fields into one field
- SlashData开发者工具榜首等你而定!!!
- [Fantan] how to design a test platform?
- 第二十四届中国科协湖南组委会调研课题组一行莅临麒麟信安调研考察
- QT video transmission
- LeetCode 1696. 跳跃游戏 VI 每日一题
- 【Seaborn】组合图表、多子图的实现
猜你喜欢
SlashData开发者工具榜首等你而定!!!
Sator推出Web3遊戲“Satorspace” ,並上線Huobi
QT 图片背景色像素处理法
Siggraph 2022 best technical paper award comes out! Chen Baoquan team of Peking University was nominated for honorary nomination
Seaborn数据可视化
Sator推出Web3游戏“Satorspace” ,并上线Huobi
A tour of grpc:03 - proto serialization / deserialization
Reflections on "product managers must read: five classic innovative thinking models"
mysql官网下载:Linux的mysql8.x版本(图文详解)
Matplotlib绘图界面设置
随机推荐
LeetCode 1186. Delete once to get the sub array maximum and daily question
rpcms获取指定分类下的文章的方法
【饭谈】那些看似为公司着想,实际却很自私的故事 (一:造轮子)
skimage学习(3)——使灰度滤镜适应 RGB 图像、免疫组化染色分离颜色、过滤区域最大值
【饭谈】Web3.0到来后,测试人员该何去何从?(十条预言和建议)
麒麟信安云平台全新升级!
L1-027 出租(Lua)
Smart logistics platform: make overseas warehouses smarter
skimage学习(2)——RGB转灰度、RGB 转 HSV、直方图匹配
【饭谈】如何设计好一款测试平台?
LeetCode 515(C#)
LeetCode 1696. Jumping game VI daily question
LeetCode 535(C#)
Pychart ide Download
邮件服务器被列入黑名单,如何快速解封?
LeetCode 1043. 分隔数组以得到最大和 每日一题
Solid function learning
Sator launched Web3 game "satorspace" and launched hoobi
Flask搭建api服务
mysql官网下载:Linux的mysql8.x版本(图文详解)