zoukankan      html  css  js  c++  java
  • Specialized Four-Digit Numbers

    Specialized Four-Digit Numbers

    Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other)
    Total Submission(s) : 19   Accepted Submission(s) : 15
    Problem Description
    Find and list all four-digit numbers in decimal notation that have the property that the sum of its four digits equals the sum of its digits when represented in hexadecimal (base 16) notation and also equals the sum of its digits when represented in duodecimal (base 12) notation. For example, the number 2991 has the sum of (decimal) digits 2+9+9+1 = 21. Since 2991 = 1*1728 + 8*144 + 9*12 + 3, its duodecimal representation is 1893(12), and these digits also sum up to 21. But in hexadecimal 2991 is BAF16, and 11+10+15 = 36, so 2991 should be rejected by your program. The next number (2992), however, has digits that sum to 22 in all three representations (including BB016), so 2992 should be on the listed output. (We don't want decimal numbers with fewer than four digits - excluding leading zeroes - so that 2992 is the first correct answer.)
     
    Input
    There is no input for this problem.
     
    Output
    Your output is to be 2992 and all larger four-digit numbers that satisfy the requirements (in strictly increasing order), each on a separate line with no leading or trailing blanks, ending with a new-line character. There are to be no blank lines in the output. The first few lines of the output are shown below.
     
    Sample Input
    There is no input for this problem.
     
    Sample Output
    2992 2993 2994 2995 2996 2997 2998 2999
     
    Source
    Pacific Northwest 2004
     
     1 #include <stdio.h>
     2 #include <stdlib.h>
     3 #include <string.h>
     4 
     5 int main()
     6 {
     7     char sum_10[5],sum_12[5],sum_16[5];
     8     int i,j,SUM_10,SUM_12,SUM_16;
     9 
    10     for(j=2992;j<=9999;j++)
    11     {
    12         itoa(j,sum_10,10);
    13         itoa(atoi(sum_10),sum_12,12);
    14         itoa(atoi(sum_10),sum_16,16);
    15         for(i=0,SUM_10=0,SUM_12=0,SUM_16=0;i<4;i++)
    16         {
    17             SUM_10+=sum_10[i]-'0';
    18 
    19             if(sum_12[i]=='a')
    20                 SUM_12+=10;
    21             else if(sum_12[i]=='b')
    22                 SUM_12+=11;
    23             else if(sum_12[i]!=0)
    24             SUM_12+=sum_12[i]-'0';
    25 
    26             if(sum_16[i]=='a')
    27                 SUM_16+=10;
    28             else if(sum_16[i]=='b')
    29                 SUM_16+=11;
    30             else if(sum_16[i]=='c')
    31                 SUM_16+=12;
    32             else if(sum_16[i]=='d')
    33                 SUM_16+=13;
    34             else if(sum_16[i]=='e')
    35                 SUM_16+=14;
    36             else if(sum_16[i]=='f')
    37                 SUM_16+=15;
    38             else if(sum_16[i]!=0)
    39                 SUM_16+=sum_16[i]-'0';
    40         }
    41         if((SUM_16==SUM_12)&&(SUM_16==SUM_10)&&(SUM_10==SUM_12))
    42             printf("%s
    ",sum_10);
    43     }
    44     return 0;
    45 }
    View Code
    转载请备注:
    **************************************
    * 作者: Wurq
    * 博客: https://www.cnblogs.com/Wurq/
    * Gitee: https://gitee.com/wurq
    **************************************
  • 相关阅读:
    HDU 2054 A == B ?(找小数点)
    javaWeb_使用标签库简化jsp
    EC2的维护更新-总结篇及有效经验分享
    SSLStrip 终极版 —— location 瞒天过海
    华为部分真机调试无法显示log问题解决
    LeetCode
    Tcl脚本调用高层API实现仪表使用和主机创建配置的自己主动化測试用例
    web工程调用hadoop集群1.2
    3DShader之移位贴图(Displacement Mapping)
    Java 学习第一天
  • 原文地址:https://www.cnblogs.com/Wurq/p/3750280.html
Copyright © 2011-2022 走看看