博客
关于我
牛客历年机试真题--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/

你可能感兴趣的文章
No 'Access-Control-Allow-Origin' header is present on the requested resource.
查看>>
No 'Access-Control-Allow-Origin' header is present on the requested resource.
查看>>
NO 157 去掉禅道访问地址中的zentao
查看>>
no available service ‘default‘ found, please make sure registry config corre seata
查看>>
No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
查看>>
no connection could be made because the target machine actively refused it.问题解决
查看>>
No Datastore Session bound to thread, and configuration does not allow creation of non-transactional
查看>>
No fallbackFactory instance of type class com.ruoyi---SpringCloud Alibaba_若依微服务框架改造---工作笔记005
查看>>
No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalanc
查看>>
No mapping found for HTTP request with URI [/...] in DispatcherServlet with name ...的解决方法
查看>>
No mapping found for HTTP request with URI [/logout.do] in DispatcherServlet with name 'springmvc'
查看>>
No module named 'crispy_forms'等使用pycharm开发
查看>>
No module named 'pandads'
查看>>
No module named cv2
查看>>
No module named tensorboard.main在安装tensorboardX的时候遇到的问题
查看>>
No module named ‘MySQLdb‘错误解决No module named ‘MySQLdb‘错误解决
查看>>
No new migrations found. Your system is up-to-date.
查看>>
No qualifying bean of type XXX found for dependency XXX.
查看>>
No qualifying bean of type ‘com.netflix.discovery.AbstractDiscoveryClientOptionalArgs<?>‘ available
查看>>
No resource identifier found for attribute 'srcCompat' in package的解决办法
查看>>