当前位置:网站首页>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;
}边栏推荐
- Global and Chinese market of insulin pens 2022-2028: Research Report on technology, participants, trends, market size and share
- Global and Chinese market of cell culture freezers 2022-2028: Research Report on technology, participants, trends, market size and share
- Financial portal related information
- Gee series: unit 6 building various remote sensing indexes in Google Earth engine
- 黑马笔记---Map集合体系
- 青训营--数据库实操项目
- Black Horse Notes - - set Series Collection
- JVM class loading mechanism
- Leetcode18题 【四数之和】递归解法
- Two implementation methods of delay queue
猜你喜欢

6.网络-基础

在线音乐播放器app
![Gee series: unit 8 time series analysis in Google Earth engine [time series]](/img/a6/648ff959af93c22dc8605215a90535.jpg)
Gee series: unit 8 time series analysis in Google Earth engine [time series]

运维工作的“本手、妙手、俗手”

Résumé de la collection de plug - ins couramment utilisée dans les outils de développement idea

Innovation never stops -- the innovation process of nvisual network visualization platform for Excel import

Fabric. JS iText superscript and subscript

摆正元素(带过渡动画)

Dark horse notes -- map set system

青训营--数据库实操项目
随机推荐
Fabric.js IText设置指定文字的颜色和背景色
Sliding window on the learning road
Gee series: unit 8 time series analysis in Google Earth engine [time series]
centos8安裝mysql8.0.22教程
460. LFU 缓存 双向链表
Gee: find the spatial distribution and corresponding time of the "greenest" in the Yellow River Basin in 2020 [pixel by pixel analysis]
kmp思想及模板代码
Leetcode18题 【四数之和】递归解法
"Original, excellent and vulgar" in operation and maintenance work
Php/js cookie sharing across domains
Visual studio import
Fabric. JS basic brush
Gee: create a new feature and set corresponding attributes
I want to understand the swift code before I learn it. I understand it
Gee: remote sensing image composite and mosaic
H5 jump applet
XSS basic content learning (continuous update)
【pyinstaller】_ get_ sysconfigdata_ name() missing 1 required positional argument: ‘check_ exists‘
ubuntu20.04安装mysql8
延时队列两种实现方式