hdu 4278 Faulty Odometer

6727064 2012-09-09 17:39:14 Accepted 4278 0MS 212K 853 B G++
若代码有错,请指出^^
分析:
  相当于将十进制转换为8进制。。。
View Code
 1 #include <cstdio>

 2 #include <cstring>

 3 #include <algorithm>

 4 

 5 using namespace std;

 6 

 7 int n, m, l, ans;

 8 int a[20];

 9 int p[11];

10 

11 int main()

12 {

13      p[0] = 1;

14      for (int i = 1; i < 11; ++i) p[i] = p[i-1] * 8;

15      while(scanf("%d", &n) == 1) {

16           if (n == 0) break;

17           l = 0;

18           m = n;

19           while(n) {

20                a[l++] = n % 10;

21                n /= 10;

22           }

23           for (int i = 0; i < l; ++i) {

24                if (a[i] == 4) a[i] = 3;

25                else if(a[i] == 5) a[i] = 4;

26                else if(a[i] == 6) a[i] = 5;

27                else if(a[i] == 7) a[i] = 6;

28                else if(a[i] == 9) a[i] = 7;          

29           }

30           ans = 0;

31           for (int i = l-1; i >= 0; --i)

32                ans += a[i]*p[i];

33           printf("%d: %d\n",m,ans);

34 

35      }

36 

37      return 0;

38 }

你可能感兴趣的:(dom)