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 BAF 16, 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 BB0 16), 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
... 依旧是submit failed,以下为我写的代码
#include <iostream>
using namespace std;
int f(int n,int x)
{
int i=,j,a[],m=;
while(n!=) {
a[i++]=n%x;
n=n/x;
}
for(j=;j<i;j++)m+=a[j];
return m;
}
int main()
{
int n,i,p,q;
for(i=;i<;i++){
n=i/+i/%+i/%+i%;
p=f(i,);
q=f(i,);
if(p==n&&q==n)cout<<i<<endl;
}
system("pause");
return ;
}

以下是提交成功AC的代码

#include <iostream>
using namespace std;
int f(int n,int x)
{
int a,m=;
while(n!=) {
a=n%x;
n=n/x;
m+=a;
}
return m;
}
int main()
{
int n,i;
for(i=;i<;i++){
n=i/+i/%+i/%+i%;
if(f(i,)==n&&f(i,)==n)cout<<i<<endl;
}
//system("pause");
return ;
}

发现我写的代码似乎太啰嗦了!!!麻烦!!许多东西完全可以省略!!!!

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

  1. [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 ...

  2. 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 ...

  3. 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'}.  ...

  4. [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 ...

  5. 利用Python【Orange】结合DNA序列进行人种预测

    http://blog.csdn.net/jj12345jj198999/article/details/8951120 coursera上 web intelligence and big data ...

  6. PAT/进制转换习题集

    B1022. D进制的A+B (20) Description: 输入两个非负10进制整数A和B(<=230-1),输出A+B的D (1 < D <= 10)进制数. Input: ...

  7. [转]http://lua-users.org/wiki/LpegTutorial

    Simple Matching LPeg is a powerful notation for matching text data, which is more capable than Lua s ...

  8. FZU 2215 Simple Polynomial Problem(简单多项式问题)

    Description 题目描述 You are given an polynomial of x consisting of only addition marks, multiplication ...

  9. Problem K 栈

    Description A math instructor is too lazy to grade a question in the exam papers in which students a ...

  10. PAT 1019

    1019. General Palindromic Number (20) A number that will be the same when it is written forwards or ...

随机推荐

  1. break,continue,return 区别

    using System;using System.Collections.Generic;using System.Text; namespace breakcontinue_test{    cl ...

  2. (转)Should I use char** argv or char* argv[]

      As you are just learning C, i recommend you to really try to understand the differences between ar ...

  3. (原)caffe中通过图像生成lmdb格式的数据

    转载请注明出处: http://www.cnblogs.com/darkknightzh/p/5909121.html 参考网址: http://www.cnblogs.com/wangxiaocvp ...

  4. Object.create函数

    创建一个具有指定原型且可选择性地包含指定属性的对象. Object.create(prototype, descriptors) 参数 prototype必需. 要用作原型的对象. 可为 null. ...

  5. linux下python3连接mysql数据库

    python语言的3.x完全不向前兼容,导致我们在python2.x中可以正常使用的库,到了python3就用不了了.比如说mysqldb 1.安装pymysql pymysql就是作为python3 ...

  6. 使导出excle文档实现ALT+Enter的效果()

    JAVA中输入什么转义字符,使导出excle文档实现ALT+Enter的效果?或者有没有其他方法可以实现. 20 JAVA中输入什么转义字符,使导出excle文档实现ALT+Enter的效果?或者有没 ...

  7. 典型的DIV CSS三行二列居中高度自适应布局

    如何使整个页面内容居中,如何使高度适应内容自动伸缩.这是学习CSS布局最常见的问题.下面就给出一个实际的例子,并详细解释.(本文的经验和是蓝色理想论坛xpoint.guoshuang共同讨论得出的.) ...

  8. SQL Server 2008空间数据应用系列二:空间索引(Spatial Index)基础

    原文:SQL Server 2008空间数据应用系列二:空间索引(Spatial Index)基础 在前一篇博文中我们学习到了一些关于地理信息的基础知识,也学习了空间参照系统,既地球椭球体.基准.本初 ...

  9. Windows 7下可以使用的各个命令语句+C#打开

    Windows 7下可以使用的各个命令语句:   control.exe /name microsoft.folderoptions 启动资源管理器的 文件夹属性 选项卡 control.exe /n ...

  10. kabina启动配置

    启动 kibana # /usr/local/kibana-4.1.1-linux-x64/bin/kibana zjtest7-redis:/usr/local/kibana-4.5.3-linux ...