Saturday, July 8, 2017

Uva problem solution 575 - Skew Binary

problem link:


Discuss:

In this problem you just have to applied simple decimal based conversion system. As the number can big enough you should use string to take input.


try yourself   before see the code


#include<bits/stdc++.h>
using namespace std;
int main()
{
long long n,i,j;
char  str[10000];
   while(scanf("%s",&str))
   {
       long long sum=0,pw,r;
       n=strlen(str);
   for(i=0;i<n;i++)
       {
           r=str[i]-'0';
           pw=pow(2,n-i)-1;
           sum+=r*pw;
       }
       if(sum==0)
       {
             break;
       }

       cout <<sum<<endl;

   }
   return 0;
}

No comments:

Post a Comment