HDU 1197 JAVA
来源:互联网 发布:java小明要到美国旅游 编辑:程序博客网 时间:2024/06/05 04:44
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进制,然后把每个 位 的数相加,最后三个合相等则是满足条件
package hlh;public class p1197 { /** * 胡龙华 */ public static void main(String[] args) { for(int i=2992;i<10000;i++){ String s = ""+i; int num = 0; for(int j=0;j<s.length();j++){ int temp = Integer.parseInt(s.charAt(j)+""); num = num +temp; } if(num==JZ(i,16) && num==JZ(i,12)){ System.out.println(i); } } } // 将n转化为R进制,然后把每个数字的和返回 private static int JZ(int N, int R) { int s = 0; int x=N/R;int y=N%R; String chs[]={"0","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15"}; int []a=new int [50];int i=0; a[0]=N%R; while(x!=0){ i++; y=x%R; a[i]=y; x=x/R; } int b[]=new int[i+1]; for(int k=0;k<i+1;k++){ // System.out.print(a[k]+" a"); b[k]=a[i-k]; //System.out.print(b[k]+" "); } for(int j=0;j<b.length;j++){ int temp = Integer.parseInt(chs[b[j]]); s = s +temp; // System.out.print(chs[b[j]]); } return s ; }}
- HDU 1197 JAVA
- hdu acm hdu 2115 Java
- Exponentiation hdu 1063 java
- hdu 1313 (Java)
- 【Java】hdu 4043
- hdu 1242 Rescue<java>
- HDU 1002 JAVA
- hdu 2092(java)
- hdu 1063 java 高精度
- hdu 1106(java)
- hdu 1073(java)
- HDU-4762 Java高精度
- hdu 1002 java
- hdu 1089 java
- JAVA hdu 2192 MagicBuilding
- hdu 1001 java
- hdu 1002 java
- hdu 1003 java
- 函数重载、重写(覆盖)和重定义(隐藏)
- 15 linux驱动模块的参数
- linux 解压 .gz 格式文件出错解决办法
- 虚拟机安装mac系统bug
- python PIL 安装
- HDU 1197 JAVA
- Apache Ranger初识
- Python中列表元素删除
- 下载Spring源文件方法
- mysql group by作用
- LinkedHashMap和HashMap的比较使用
- 微信公众号三方平台开发【component_verify_ticket篇】
- fiddler抓包时出现了tunnel to ......443
- Springboot中对jpa动态查询条件的封装