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;
}


阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页