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. OpenCV——无法启动此程序,丢失**解决办法

    OpenCV程序运行时,有时出现以下错误: 解决方法: 在opencv安装目录下找到这个链接库,将其复制到以下指定目录中 我的链接库目录为:E:\Program files\opencv\build\ ...

  2. (原)Ubuntu14中安装GraphicsMagick

    转载请注明出处: http://www.cnblogs.com/darkknightzh/p/5661439.html 参考网址: http://comments.gmane.org/gmane.co ...

  3. Linux安装系统注意事项及系统初始化

      Linux安装系统注意事项 1.分区 学习用途: /boot:200M /swap :内存的1到2倍 /:根据需要分配大小,比如虚拟机下总空间是15G,那么可以分配8——10G跟/分区,如果是生产 ...

  4. jQuery模拟瀑布流布局

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  5. FloatingActionButton 完全解析[Design Support Library(2)]

    一.简单使用 布局: <android.support.design.widget.FloatingActionButton android:layout_width="wrap_co ...

  6. php word转HTML

    因为安装的的xampp不知道如何查看我的Apache版本是多少,就先把com.allow_dcom=true打开了,但是仍旧报错说找不到com类,然后就把下面的extension扩展添加到php.in ...

  7. 超级密码(dfs)

    超级密码233 Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total S ...

  8. MVC4商城项目四:应用Bundle捆绑压缩技术

    从MVC4开始,我们就发现,项目中对Global.asax进行了优化,将原来在MVC3中使用的代码移到了[App_Start]文件夹下,而Global.asax只负责初始化.其中的BundleConf ...

  9. 纯js实现积木(div)拖动效果

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  10. WPF 资源收集

    转载地址:http://www.cnblogs.com/zhoujg/archive/2009/11/04/1596195.html OpenExpressApp的UI现在是使用WPF,所以熟悉WPF ...