L1-017. 到底有多二
来源:互联网 发布:快排阀能在淘宝上卖啊 编辑:程序博客网 时间:2024/06/06 00:06
L1-017. 到底有多二
时间限制
400 ms
内存限制
65536 kB
代码长度限制
8000 B
判题程序
Standard
作者
陈越
一个整数“犯二的程度”定义为该数字中包含2的个数与其位数的比值。如果这个数是负数,则程度增加0.5倍;如果还是个偶数,则再增加1倍。例如数字“-13142223336”是个11位数,其中有3个2,并且是负数,也是偶数,则它的犯二程度计算为:3/11*1.5*2*100%,约为81.82%。本题就请你计算一个给定整数到底有多二。
输入格式:
输入第一行给出一个不超过50位的整数N。
输出格式:
在一行中输出N犯二的程度,保留小数点后两位。
输入样例:-13142223336输出样例:
81.82%
我的代码
#include<iostream>#include<stdio.h>using namespace std;int main(){string str;cin>>str;int len = str.length();int count=0;for(int i=0;i<len;i++){if(str[i]=='2'){count++;}}if(str[0]=='-'){len--;}double ans = (double)count/(double)len;if(str[0]=='-'){ans*=1.5;}if((str[str.length()-1]-'0')%2==0){ans*=2;}printf("%.2lf%%",ans*100);return 0;}
阅读全文
0 0
- L1-017. 到底有多二
- L1-017. 到底有多二
- L1-017. 到底有多二
- L1-017. 到底有多二
- L1-017. 到底有多二
- L1-017. 到底有多二
- L1-017. 到底有多二
- L1-017. 到底有多二
- L1-017. 到底有多二
- L1-017. 到底有多二
- L1-017. 到底有多二
- L1-017. 到底有多二
- L1-017. 到底有多二
- L1-017. 到底有多二
- L1-017. 到底有多二
- L1-017. 到底有多二
- L1-017. 到底有多二 Java
- PAT L1-017. 到底有多二
- C语言实现: 从尾到头打印链表
- java 杨辉三角形
- 你所不知道的++i,和i++
- Python 入门第一天:安装Beautifulsoup4遇到的问题
- linux下实时查看tomcat运行日志
- L1-017. 到底有多二
- lucene源码-lock和directory--2
- 解析JSON
- redis 各种操作
- MySQL 5.6 for Windows 解压缩版配置安装
- vi编辑器基本操作
- Android
- HTTP协议与HTTPS协议的区别
- iOS App上架流程(2017详细版)