pat:L1-017. 到底有多二
来源:互联网 发布:oracle sql 优化 分析 编辑:程序博客网 时间:2024/06/05 09:39
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>#include <string.h>using namespace std;int main(){ /* -13142223336 */ char a[100]; scanf("%s",a); int len =strlen(a); int b[100]; double w,count=0.0; for ( int i=0; i<len; i++ ) { b[i] = a[i]-'0'; if(b[i]==2) { count++; } } if( b[0]==-3 ) { w=(count/(len-1))*1.5; if( b[len-1]%2==0 ) w = w*2.0; } else { w=count/len; if( b[len-1]%2==0) w = w*2.0; } w = w*100.0; printf("%.2f%%",w); return 0;}
阅读全文
0 0
- PAT L1-017. 到底有多二
- PAT L1-017. 到底有多二
- pat:L1-017. 到底有多二
- PAT团队赛L1-017.到底有多二
- L1-017. 到底有多二-PAT团体程序设计天梯赛GPLT
- 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. 到底有多二
- TeamCity配置代码自动化发布本机java项目到远程测试服务器tomcat下
- 数论初步
- C/C++中的回调函数
- java中volatile关键字
- 既然堆已经可以管理变量的生命周期,那么栈的作用个是什么?
- pat:L1-017. 到底有多二
- python 爬虫-0:我的计划
- python 负数时间戳转换/转换1970年之前的时间戳
- Centos 安装Git步骤及方法总结
- 小型调度框架
- 如何获取WebView内容高度
- [codeforces] Gym
- linux命令之-dmesg详解
- 科学计算法转换问题