Accepted solution

UVA 575 - Skew Binary Solution

Open original problem
Source code

#include <iostream>

#include<vector>

#include<math.h>

using namespace std;

int main()

{

    string value;

    int len,i;

    long long sum=0;

    while(cin>>value)

    {

        if(value=="0")

        {

            break;

        }

        long long int temp=1;

        len=value.length();

        for(int i=len-1; i>=0; i--)

        {

            if(value[i]=='1')

            {

                sum += (pow(2,temp)-1);

            }

            else if(value[i]=='2')

            {

                sum+= (2*(pow(2,temp)-1));

            }

            temp++;

        }

        cout<<sum<<endl;

        sum=0;

        temp=1;

    }

    return 0;

}
Join the discussion

Add your comment