博客
关于我
牛客历年机试真题--skew数(入门级)
阅读量:342 次
发布时间:2019-03-04

本文共 928 字,大约阅读时间需要 3 分钟。

KY45 skew数

刷题链接: .

题目描述:

在 skew binary 表示中,第 k 位的值 x[k] 表示 x[k]×(2^(k+1)-1)。每个位上的可能数字是 0 或 1,最后面一个非零位可以是 2,例如,10120(skew) = 1×(2^5-1) + 0×(2^4-1) + 1×(2^3-1) + 2×(2^2-1) + 0×(2^1-1) = 31 + 0 + 7 + 6 + 0 = 44。前十个 skew 数是 0、1、2、10、11、12、20、100、101、以及 102。

输入描述:

输入包括多组数据,每组数据包含一个 skew 数。

输出描述:

对应每一组数据,输出相应的十进制形式。结果不超过 2^31-1。

示例1:

输入:

101202000000000000000000000000000001010000000000000000000000000000001110011111000001110000101101102000

输出:

44214748364632147483647471041110737

我的代码:(长整型可以用字符数组存储)

#include
#include
#include
int main(){ char x[100]; while(scanf("%s",&x)!=EOF) { int len,k=1,sum=0; len=strlen(x); for(int i=len-1;i>=0;i--) { k=k*2; sum+=(k-1)*(x[i]-'0'); } printf("%d\n",sum); } return 0;}

参考代码:(顺序遍历,使用pow函数)

#include
#include
#include
int main(){ char x[100]; while(scanf("%s",&x)!=EOF) { int len,sum=0; len=strlen(x); for(int i=0;i

转载地址:http://grpe.baihongyu.com/

你可能感兴趣的文章
mysql-cluster 安装篇(1)---简介
查看>>
mysql-connector-java各种版本下载地址
查看>>
mysql-EXPLAIN
查看>>
mysql-group_concat
查看>>
MySQL-redo日志
查看>>
MySQL-【1】配置
查看>>
MySQL-【4】基本操作
查看>>
Mysql-丢失更新
查看>>
Mysql-事务阻塞
查看>>
Mysql-存储引擎
查看>>
mysql-开启慢查询&所有操作记录日志
查看>>
MySQL-数据目录
查看>>
MySQL-数据页的结构
查看>>
MySQL-架构篇
查看>>
MySQL-索引的分类(聚簇索引、二级索引、联合索引)
查看>>
Mysql-触发器及创建触发器失败原因
查看>>
MySQL-连接
查看>>
mysql-递归查询(二)
查看>>
MySQL5.1安装
查看>>
mysql5.5和5.6版本间的坑
查看>>