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

题意:输入一个十进制数,看这个十进制的数的各个位数上的和,和它的12进制和16进制上的各个位数上的和是不是相等,相等就输出。

(十进制的数范围[2992-9999])

public class Main{
public static void main(String[] args) {
for(int i=2992;i<=9999;i++){
int a = i/1000+(i/100)%10+(i/10)%10+i%10;
String str = Integer.toString(i, 12);
//System.out.println(str);
int b = 0;
for(int j=0;j<str.length();j++){
switch(str.charAt(j)){
case 'a':b=b+10;break;
case 'b':b=b+11;break;
default:b=b+(new Integer(str.charAt(j)+""));
}
}
if(a!=b){
continue;
}
int c=0;
str = Integer.toString(i, 16);
//System.out.println(str);
for(int j=0;j<str.length();j++){
switch(str.charAt(j)){
case 'a':c=c+10;break;
case 'b':c=c+11;break;
case 'c':c=c+12;break;
case 'd':c=c+13;break;
case 'e':c=c+14;break;
case 'f':c=c+15;break;
default:c=c+(new Integer(str.charAt(j)+""));
}
}
if(a!=c){
continue;
}
System.out.println(i);
} } }

HDOJ 1197 Specialized Four-Digit Numbers的更多相关文章

  1. 【HDOJ】1197 Specialized Four-Digit Numbers

    水题,暴力可解. #include <iostream> using namespace std; int chg(int n, int base); int main() { int i ...

  2. HDU 1197 Specialized Four-Digit Numbers

    Specialized Four-Digit Numbers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K ...

  3. HDU 1197 Specialized Four-Digit Numbers (枚举+进制转化,简单)

    题意:让求从2992-9999中所有数字,满足10进制各位之和和12进制和16进制各位数字之和相等. 析:没啥可说的,只能枚举从2992-9999,每个进制都算一下. 代码如下: #include & ...

  4. hdoj 2817 A sequence of numbers【快速幂】

    A sequence of numbers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  5. 【HDOJ】1061 Rightmost Digit

    这道题目可以手工打表,也可以机器打表,千万不能暴力解,会TLE. #include <stdio.h> #define MAXNUM 1000000001 ][]; int main() ...

  6. [Swift]LeetCode902. 最大为 N 的数字组合 | Numbers At Most N Given Digit Set

    We have a sorted set of digits D, a non-empty subset of {'1','2','3','4','5','6','7','8','9'}.  (Not ...

  7. 902. Numbers At Most N Given Digit Set

    We have a sorted set of digits D, a non-empty subset of {'1','2','3','4','5','6','7','8','9'}.  (Not ...

  8. LeetCode902. Numbers At Most N Given Digit Set

    题目: We have a sorted set of digits D, a non-empty subset of {'1','2','3','4','5','6','7','8','9'}.  ...

  9. [LeetCode] 902. Numbers At Most N Given Digit Set 最大为 N 的数字组合

    We have a sorted set of digits D, a non-empty subset of {'1','2','3','4','5','6','7','8','9'}.  (Not ...

随机推荐

  1. SQL语句查询结果额外加入一列序号自己主动添加

    sqlserver 能够用row_number函数实现 例如以下: SELECT *,row_number() OVER(ORDER BY score(列名) DESC) AS rank FROM s ...

  2. HDU 1166 敌兵布阵(线段树)

    题目地址:pid=1166">HDU 1166 听说胡浩版的线段树挺有名的. 于是就拜訪了一下他的博客.详情戳这里.于是就全然仿照着胡浩大牛的风格写的代码. 至于原理.鹏鹏学长已经讲的 ...

  3. AMD 规范以及如何将AMD转变为CommonJS

    原文:http://villadora.me/2014/05/23/amd-define-and-how-to-translate-amd-to-commonjs/ CommonJS和AMD的争论已经 ...

  4. OKHttp源码解析

    http://frodoking.github.io/2015/03/12/android-okhttp/ Android为我们提供了两种HTTP交互的方式:HttpURLConnection 和 A ...

  5. RHEL7下PXE+FTP+Kickstart无人值守安装操作系统

    1.配置yum源 vim /etc/yum.repos.d/development.repo [development] name=yum server baseurl=file:///mnt ena ...

  6. mui实现退出当前应用

    var first = null; var showMenu = false; mui.back = function() { if(showMenu) { closeMenu();} else { ...

  7. 单线程与多线程的简单示例(以Windows服务发短信为示例)

    单线程示例: public delegate void SM(); SM sm = new SM(() =>    {                    while (true)       ...

  8. JAVA Hibernate别名排序问题

    今天在做统计功能的时候遇到这样一个问题,由于查询结果为统计的数据,即使用了sum方法生成的字段, else trigger_count end) as hitCount from TriggerSta ...

  9. file控件change事件触发问题

    最近,项目中需要用到一个图片上传的功能,我用的file控件来选取图片文件,然后利用js读取文件来预览图片,最后再根据用户的操作来决定是否上传文件. 其中碰到了一个奇怪的问题:在选取完第一张图片,并上传 ...

  10. sql数据库之间数据的转录

    private void Form1_Load(object sender, EventArgs e) { BindDataBase(combDataBaseNew, , ""); ...