当前位置:网站首页>Zzuli:1068 binary number
Zzuli:1068 binary number
2022-07-02 05:30:00 【Don't explode】
Title Description
Put a binary number , Convert to the corresponding decimal number .
Input
Enter one that contains only ’0’ and ’1’ String , End with a carriage return , Represents a binary number . The binary number has unsigned bits , Length not exceeding 31.
Output
Output an integer , Is the decimal number corresponding to the binary number .
The sample input Copy
100000000001
Sample output Copy
2049
Tips
(1) Integer operations should be avoided pow And so on. double Type function , To avoid errors caused by truncation and rounding . (2) You can use the idea of recursion , Make full use of intermediate results . Similar ideas can refer to Qin Jiushao algorithm . Qin Jiushao algorithm is a polynomial simplification algorithm proposed by Qin Jiushao, a mathematician in Southern Song Dynasty . Calculate a polynomial f(x) = a0*xn + a1*x(n-1) + ... + an It only needs n The multiplication and n Time in addition . The principle is a polynomial of degree f(x) It can be written in parentheses as follows :f(x) =(( (a0*x + a1)*x + a2) * x + ... an-1) * x + an. Remove brackets from inside out to calculate , It only needs n The multiplication and n Time in addition .
This question outputs binary numbers from high to low , Corresponding polynomial coefficients a0, a1,....,an, and x The value of is 2. The recursive process is as follows :
d = 0;
while( ch = getchar(), ch != '\n')
d = d * 2 + (ch - '0');
#include <stdio.h>
int main()
{
char ch;
int d=0;
while(scanf("%c",&ch),ch!='\n')
{
d=d*2+(ch-'0');
}
printf("%d",d);
return 0;
}
边栏推荐
- Gee: explore the characteristics of precipitation change in the Yellow River Basin in the past 10 years [pixel by pixel analysis]
- 6.网络-基础
- 操作符详解
- 运维工作的“本手、妙手、俗手”
- 指针使用详解
- H5 jump applet
- Fabric. JS activation input box
- Gee: create a new feature and set corresponding attributes
- Global and Chinese markets for marine selective catalytic reduction systems 2022-2028: Research Report on technology, participants, trends, market size and share
- Fabric.js 将本地图像上传到画布背景
猜你喜欢
【pyinstaller】_get_sysconfigdata_name() missing 1 required positional argument: ‘check_exists‘
Gee: use of common mask functions in remote sensing image processing [updatemask]
Nodejs (02) - built in module
Record sentry's path of stepping on the pit
Dark horse notes -- map set system
Principle and implementation of parallax effect
kmp思想及模板代码
指针使用详解
6. Network - Foundation
Gee series: unit 8 time series analysis in Google Earth engine [time series]
随机推荐
7.1 Résumé du concours de simulation
Fabric.js 右键菜单
No logic is executed after the El form is validated successfully
Common protocols and download paths of NR
Creation and destruction of function stack frames
7.1 simulation summary
Fabric. JS upload local image to canvas background
Fabric. JS basic brush
Basic use of form
ERP management system development and design existing source code
Global and Chinese market of insulin pens 2022-2028: Research Report on technology, participants, trends, market size and share
Gee dataset: chirps pentad high resolution global grid rainfall dataset
Feign realizes file uploading and downloading
Operator details
Leetcode 18 problem [sum of four numbers] recursive solution
金融门户相关信息
kmp思想及模板代码
简单封装 js并应用
Innovation never stops -- the innovation process of nvisual network visualization platform for Excel import
生成二维码