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 ...
随机推荐
- 循序渐进DB2(第2版)——DBA系统管理、运维与应用案例
<循序渐进DB2(第2版)——DBA系统管理.运维与应用案例> 基本信息 作者: 牛新庄 出版社:清华大学出版社 ISBN:9787302323013 上架时间:2013-7-3 出 ...
- [Javascript] Advanced Reduce: Common Mistakes
Take away: Always check you ruturn the accumulator Always pass in the inital value var data = [" ...
- curl_setopt函数相关应用及介绍(转)
一.要想使用curl_setopt 这个函数必须在服务器里边进行编译curl这个组件,怎么安装编译这个组件请具体到google搜索 二.curl_setopt的php帮助文档的解释 bool curl ...
- Android应用程序之间共享文字和图片(一)
以下为TestReceiveShare1工程 MainActivity如下: package cn.testreceiveshare1; import java.util.ArrayList; imp ...
- Laravel No such file or directory in /bootstrap/autoload.php on line 17
具体错误如下: Warning: require(../vendor/autoload.php) [function.require]: failed to open stream: No such ...
- 6、第六课,js jquery20150928
1.声明事件,给事件添加动作 function MyClick() { alert("这是我的第一个js") } 2.js特点 A.js区分大小写 B.弱类型变量,定义一个变量 v ...
- python单元测试之unittest
unittest是python标准库,从2.1开始就有. 标准的使用流程: 1:实现一个unittest.TestCase的子类 2:在其中定义以_test开头的实例函数 3:用unittest.ma ...
- tomcat startup.sh提示java.lang.OutOfMemoryError: PermGen space
JAVA_OPTS="-server -XX:PermSize=512M -XX:MaxPermSize=1024m"if [ -z "$LOGGING_MANAGER& ...
- Android Design Support Library: 学习CoordinatorLayout
简述 CoordinatorLayout字面意思是"协调器布局",它是Design Support Library中提供的一个超级帧布局,帮助我们实现Material Design ...
- 使用URL读取网络图片资源
URL(Uniform Resource Locator) 对象代表统一资源定位器. 代码如下: public class MainActivity extends ActionBarActivity ...