当前位置:网站首页>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;
}
边栏推荐
- ThreadLocal memory leak
- Fabric.js 背景不受视口变换影响
- Nodejs (02) - built in module
- 2022-2-14 learning xiangniuke project - Section 7 account setting
- Fabric. JS iText set italics manually
- Global and Chinese market of travel data recorder (VDR) 2022-2028: Research Report on technology, participants, trends, market size and share
- Ls1046nfs mount file system
- Gee: create a new feature and set corresponding attributes
- 简单封装 js并应用
- JVM class loading mechanism
猜你喜欢
随机推荐
Visual Studio导入
Fabric.js 激活输入框
Opencv LBP features
Operator details
金融门户相关信息
Fabric. JS gradient
指针使用详解
Collectors.groupingBy 排序
7.1 simulation summary
Global and Chinese market of insulin pens 2022-2028: Research Report on technology, participants, trends, market size and share
Fabric.js 居中元素
2022-2-15 learning xiangniuke project - Section 8 check login status
Fabric.js 自由绘制矩形
Database batch insert data
Draw a wave chart_ Digital IC
Fabric. JS 3 APIs to set canvas width and height
Disable access to external entities in XML parsing
Fabric.js 圆形笔刷
Fabric. JS round brush
数据库批量插入数据