Guest User

575 Skew Binary

a guest
Dec 12th, 2012
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.45 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<math.h>
  4.  
  5. int main()
  6. {
  7.     char str[20000];
  8.     long long int i,sum,len,n,power,j;
  9.     while(gets(str)!=NULL)
  10.     {
  11.     if(str[0]=='0')
  12.         break;
  13.     else
  14.     {
  15.         len=strlen(str);
  16.         sum=0;
  17.         for(i=len,j=0;i>=1;i--,j++)
  18.         {
  19.           if(str[j]!='0')
  20.           {
  21.           power=(pow(2,i)-1);
  22.           sum=sum+((str[j]-'0')*power);
  23.           }
  24.  
  25.         }
  26.  
  27.     printf("%lld\n",sum);
  28.     }
  29.     }
  30.     return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment