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
    **************************************
  • 相关阅读:
    ORACLE批量更新四种方法比较
    ra_customer_trx_lines_all 应收发票行
    Toad for Oracle –> Debug by APPS
    应收帐款汇总
    spring3.0.5的rmi集成使用
    java synchronized详解
    用spirng和hessian构建分布式应用(远程接口)的方法(2)
    memcached——分布式内存对象缓存系统
    用spirng和hessian构建分布式应用(远程接口)的方法(1)
    如何在Spring中集成Hessian框架
  • 原文地址:https://www.cnblogs.com/Wurq/p/3750280.html
Copyright © 2011-2022 走看看