POJ 2973 skew数 解题报告

POJ 2973 skew数 解题报告

编号:2973

 

考查点:数制转换

 

思路:其它进制转换为10进制问题,存在等比和非等比两种,书上说的..

 

提交情况:此题easy,轻松AC

 

Source Code

 1 
 2 //poj grids 2973
 3 #include <iostream>
 4 #include <string.h>
 5 using namespace std;
 6 
 7 long mi(int key,int count)
 8 {
 9     int temp = 1;
10     while (count--)
11     {
12         temp *= key;
13     }
14     return temp-1;
15 }
16 
17 int main()
18 {
19     while(1)
20     {
21         char ch[1024];
22         cin>>ch;
23         int len = strlen(ch);
24         if (*ch=='0')
25         {
26             break;
27         }
28         if (len>=31)
29         {
30             cout<<mi(2,31)<<endl;
31         }
32         else
33         {
34             long sum = 0;
35             int len = strlen(ch);
36             for (int i=len-1;i>=0;i--)
37             {
38                 int temp = ch[i]-'0';
39                 if (temp)
40                 {
41                     sum += temp*mi(2,len-i);
42                 }
43             }
44             cout<<sum<<endl;
45         }
46 
47     }
48 }

 

总结:要注意intlong的长度问题,一般这种进制转换都是用字符串来装数.

 

 

                                                       By   Ns517

                                                      Time 09.01.21

posted @ 2009-01-21 22:15  端木  阅读(547)  评论(0编辑  收藏  举报