首页 > 试题广场 >

skew数

[编程题]skew数
  • 热度指数:23583 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32M,其他语言64M
  • 算法知识视频讲解
在 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

输入

10120
200000000000000000000000000000
10
1000000000000000000000000000000
11
100
11111000001110000101101102000

输出

44
2147483646
3
2147483647
4
7
1041110737
头像 立志实干
发表于 2021-03-01 14:34:06
// write your code here cpp //这一天都服了#include <cmath> str[i]-'0' pow(2,j)-1 sum+=(str[i]-'0')*(pow(2,j)-1); #include <iostream> #i 展开全文
头像 Coder_Karl
发表于 2022-03-15 00:55:28
#include <stdio.h> #include <string.h> #include <math.h> #define MAX 32 int main(void) {    展开全文
头像 DioDid
发表于 2022-02-02 19:50:52
法1: 使用long long这种类型,是存不下输入的大整数的 所以以下的程序,虽然逻辑上是正确的,但是实际上会出错 #include <stdio.h> long power(long a,long b)//a^b { long M=a; while(--b) 展开全文
头像 Javker丶鑫
发表于 2021-03-17 23:31:10
获取s.length()后给一个j作为指针获取2的多少次方,常规for遍历,用好pow函数计算即可 import java.util.Scanner; public class Main { public static void main(String[] args) { 展开全文
头像 牛客637195166号
发表于 2022-09-01 15:59:55
直接计算即可 #include <stdio.h> #include <string.h> #include <math.h> #define N 100 int main() {  &n 展开全文
头像 烤肉__
发表于 2022-01-21 11:55:13
#include <iostream> #include <string> #include <algorithm> using namespace std; int main() { string skew; while (cin >&g 展开全文
头像 宁静的冬日
发表于 2022-03-05 10:10:56
【C++】已通过 #include<iostream> #include<string> using namespace std; //返回2的i次方 long long int f(int i) { long long int result = 1; while (i 展开全文
头像 鞣氮琮脊
发表于 2022-02-09 10:16:19
#include <stdio.h> #include <string.h> #include <math.h> const int MAXN = 100; char x[MAXN]; int main() { while (scanf("%s", x)!=EOF 展开全文
头像 渺小小螃蟹
发表于 2021-05-12 14:25:33
#include<iostream> #include<cstdio> #include<string> #include<cstring> #include<math.h> using namespace std; long int 展开全文
头像 牛客652687585号
发表于 2022-02-14 16:41:25
#include<iostream> #include<cstdio> #include<string> #include<cmath> using namespace std; int main(){  &nb 展开全文