zrq495
www.zrq495.com

\begin{displaymath}10120_{skew} = 1 \times (2^5 - 1) + 0 \times (2^4-1) + 1 \tim...
...2 \times (2^2-1) + 0 \times (2^1-1)
= 31 + 0 + 7 + 6 + 0 = 44.
\end{displaymath}

看懂上图就出题了,注意给出的数字很长,可以用字符数组存放 。

代码如下:

 1 #include<iostream>
 2 #include<cmath>
 3 #include<cstring>
 4 
 5 using namespace std;
 6 
 7 int main()
 8 {
 9     int n, s;
10     int i;
11     char str[40];
12     while(cin >> str, strcmp(str, "0"))
13     {
14         s=0;
15         n=strlen(str);
16         for (i=0; i<n; i++)
17         {
18             s+=(str[i]-'0')*(pow(2, n-i)-1);
19         }
20         cout << s << endl;
21     }
22     return 0;
23 }
posted on 2012-07-31 16:56  zrq495  阅读(182)  评论(0编辑  收藏  举报