zoukankan      html  css  js  c++  java
  • (Problem 16)Power digit sum

    215 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26.

    What is the sum of the digits of the number 21000?

    题目大意:

    题目大意:

    215 = 32768 并且其各位之和为 is 3 + 2 + 7 + 6 + 8 = 26.

    21000 的各位数之和是多少?

    // (Problem 16)Power digit sum
    // Completed on Sun, 17 Nov 2013, 15:23
    // Language: C
    //
    // 版权所有(C)acutus   (mail: acutus@126.com) 
    // 博客地址:http://www.cnblogs.com/acutus/
    #include <stdio.h> 
    #include <stdbool.h>
    
    void solve(void)
    {
        int a[100000] = {0};
        int n, sum, i, j;
        n = sum = 0;
        a[0] = 1;
        for(i = 0; i < 1000; i++) {  //以1000进制的方法存储
            for(j = 0; j <= n; j++) {
                a[j] *= 2;
            }
            for(j = 0; j <= n; j++) {
                if(a[j] >= 10000) {
                    a[j] %= 10000;
                    a[j+1]++;
                    n++;
                }
            }
        }
        for(i = 0; i <= n; i++) {
            sum += a[i] / 10000;
            a[i] %= 10000;
            sum += a[i] / 1000;
            a[i] %= 1000;
            sum += a[i] / 100;
            a[i] %= 100;
            sum += a[i] / 10;
            a[i] %= 10;
            sum += a[i];
    
        }
        printf("%d
    ",sum);
    }
    
    int main(void)
    {
        solve();
        return 0;
    }
    Answer:
    1366
  • 相关阅读:
    工作中问题的总结1
    linux问题故障
    时间转换
    Tips
    总结
    方向
    同步&异步-阻塞&非阻塞
    IO 之 mark()、reset()
    GC日志分析
    JDK 部分工具使用方法
  • 原文地址:https://www.cnblogs.com/acutus/p/3545390.html
Copyright © 2011-2022 走看看