2018山东大学acm校赛B

YangFan's Number


YangFan is a wayward boy who likes to count in his own way.

The number he writes may be 0 or 1 for each digit, and the last non-zero digit may be 2, and the value of the k-th digit xk denotes CodeCogsEqn.gif.

For example:

CodeCogsEqn(1).gif

                   CodeCogsEqn(2).gif

Input

The input contains one or more lines, each line contains an integer n. If n = 0 means the input is over, otherwise n is a number written by YangFan.

Output

For each number written by YangFan, output its decimal representation. After conversion to decimal, n < 2^31.

Sample Input 1 

100000002
110
11102
0

Sample Output 1

513
10
55

这个题很郁闷,一开始看题看错了,以为输入的直接是十进制,然后写了个高精加,发现还是wa,就继续身体发现并不是10进制,用字符数组储存后进行单位运算直接a

#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n,m,i,j,k;
    char a[100000],temp;long long sum;
    temp=getchar();

    while(temp!='0')
    {i=0;
        sum=0;
        memset(a,0,sizeof(a));
        while(temp!='\n')
        {
            a[i++]=temp;
            temp=getchar();
        }
        for(i-=1,j=1;i>=0;--i,++j)
        {
            sum+=(a[i]-'0')*(pow(2,j)-1);
        }
        cout<<sum<<endl;
        temp=getchar();
    }


    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值