HDOJ 1197 Specialized Four-Digit Numbers
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的更多相关文章
- 【HDOJ】1197 Specialized Four-Digit Numbers
		水题,暴力可解. #include <iostream> using namespace std; int chg(int n, int base); int main() { int i ... 
- HDU 1197 Specialized Four-Digit Numbers
		Specialized Four-Digit Numbers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ... 
- HDU 1197 Specialized Four-Digit Numbers (枚举+进制转化,简单)
		题意:让求从2992-9999中所有数字,满足10进制各位之和和12进制和16进制各位数字之和相等. 析:没啥可说的,只能枚举从2992-9999,每个进制都算一下. 代码如下: #include & ... 
- hdoj 2817 A sequence of numbers【快速幂】
		A sequence of numbers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ... 
- 【HDOJ】1061 Rightmost Digit
		这道题目可以手工打表,也可以机器打表,千万不能暴力解,会TLE. #include <stdio.h> #define MAXNUM 1000000001 ][]; int main() ... 
- [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 ... 
- 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 ... 
- 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'}. ... 
- [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 ... 
随机推荐
- Linux查看代码量
			利用find xargs wc可方便的计算出某个目录下源文件的代码量find sourcecode_dir_path -type f -name "*.c" -print0 | ... 
- oracle的concat的用法
			select concat( concat( concat( ( select area_name from ec_area where area_id ), ( select area_name f ... 
- java09数组的使用
			/** * 数组:存储相同数据类型的一组数据! * 声明一个数组就是在内存中开辟了一连串的连续空间! * * 数组和String 都是 引用数据类型 * 数组的使用 */ @Test public v ... 
- ASP.NET-FineUI开发实践-6(二)
			1.上回说到修改以前的会出现好几个5: 这是因为新增时是只新增到最后一行,所以点击选好了就跑到最后一行了,而且行号不会累积,只加到初始化的行号. 其实js里是有插入的,例子里可以插入到第一行,新增是a ... 
- nyoj 44
			//nyoj 44 //和上面一题一样,求子串和,但是代码非常简洁..... 时间复杂度为n #include <iostream> using namespace std; int ma ... 
- 关于导出oracle多个表的建表语句DLL,生成.sql语句。
			--('TABLE','LINE','ODS_XX')这里面的表和用户都需要大写.如果表名用户名不大写会报这个错误:对象 "emp" 属于类型 TABLE, 在方案 "s ... 
- 导出EXCEL(转转)
			)) content.AppendFormat("<td style='vnd.ms-excel.numberformat:#, ... 
- 【PHP】新浪、淘宝的地区 API调用
			/推荐使用新浪的: $ch = curl_init(); $url = "http://ip.dpool.sina.com.cn/iplookup/iplookup.php?format=j ... 
- ADODB的应用
			<?php include_once ('adodb5/adodb.inc.php'); $db = NewADOConnection ('mysql'); $db->Connect(&q ... 
- MySQL执行外部sql脚本
			1:-/mysql_test/test.sql create table student( sno int not null primary key auto_increment, sname ) n ... 
