代码如下:
/* * *Declaration:The author of <<Accelerated C++>> has wrote in the end of that book: As you look for reading materimal, keep in mind that books on the shelf do not make you a better programmer. Ultimately, the only way to improve your programming is to write programs. >这些程序来自一些ACM书籍,作者只为提高编程能力,实现书中例题或练习。如有侵权,请联系作者,作者将立即删除。 * *联系邮箱:mingxinglai#gmail.com * */ #include <stdio.h> #include <string.h> #include <math.h> int main(int argc, char* argv[]) { int i, k, base[31], sum; char skew[32]; base[0] = 1; for( i = 1; i < 31; i++) base[i] =(int)(pow(2,i+1) - 1); while(1) { scanf("%s",skew); if( strcmp(skew,"0") == 0) break; sum = 0; k = strlen( skew ); for( i = 0; i < strlen( skew ); i++) { k--; sum += (skew[i] - '0') * base[k]; } printf("%d\n",sum); } return 0; }