Sunday, February 27, 2011

575 - Skew Binary


#include<iostream>
#include<cstring>
#include<cstdlib>
using namespace std;
int main()
{
    char n[50];
    long int N,i,l,p;
    //freopen("in.txt","r",stdin);
    while(cin>>n)
    {
        if(!strcmp(n,"0"))break;
        N=0;p=1;
        l=strlen(n);
    //    cout<<n<<endl;
        for(i=l-1;i>=0;i--)
        {
            p*=2;
            N+=(n[i]-48)*(p-1);
        }
        cout<<N<<endl;
    }
    exit(0);
}

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.