当前位置:网站首页>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;
}边栏推荐
猜你喜欢

Software testing learning - day 4

Fabric.js 居中元素
![Gee series: unit 7 remote sensing image classification using GEE [random forest classification]](/img/01/ba9441b7b1efaed85c464316740edb.jpg)
Gee series: unit 7 remote sensing image classification using GEE [random forest classification]

Disable access to external entities in XML parsing

数据的储存

Gee series: Unit 2 explore datasets
![Gee series: unit 10 creating a graphical user interface using Google Earth engine [GUI development]](/img/78/a17034d4b77d5c0dbe741f84a8ecd7.jpg)
Gee series: unit 10 creating a graphical user interface using Google Earth engine [GUI development]

Gee: remote sensing image composite and mosaic

RNN recurrent neural network
![Gee: explore the characteristics of precipitation change in the Yellow River Basin in the past 10 years [pixel by pixel analysis]](/img/ff/59956c2323567cc614458a2bccb642.jpg)
Gee: explore the characteristics of precipitation change in the Yellow River Basin in the past 10 years [pixel by pixel analysis]
随机推荐
Mysql基础---查询(1天学会mysql基础)
Opencv LBP features
Gee series: Unit 1 Introduction to Google Earth engine
Fabric.js 自由绘制矩形
线程池概述
[technical notes-08]
Gee series: Unit 3 raster remote sensing image band characteristics and rendering visualization
Fabric.js 圆形笔刷
Gee: use of common mask functions in remote sensing image processing [updatemask]
Visual studio import
Using QA band and bit mask in Google Earth engine
Online English teaching app open source platform (customized)
【pyinstaller】_ get_ sysconfigdata_ name() missing 1 required positional argument: ‘check_ exists‘
线程池批量处理数据
Global and Chinese market of cell culture freezers 2022-2028: Research Report on technology, participants, trends, market size and share
With an amount of $50billion, amd completed the acquisition of Xilinx
Straighten elements (with transition animation)
【pyinstaller】_get_sysconfigdata_name() missing 1 required positional argument: ‘check_exists‘
操作符详解
Operator details