poj2196

时间:2022-08-22 21:29:30
Specialized Four-Digit Numbers
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 7238   Accepted: 5285

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 189312, 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
...

Source

Pacific Northwest 2004
 #include <iostream>

 using namespace std;

 int digits(int x)
{
int a = x/;
int sum = ;
sum +=a;
a = x%/;
sum +=a;
a = x%%/;
sum +=a;
a = x%%%;
sum +=a;
return sum;
}
int digits_12(int x)
{
int num_12[];
for(int i = ;i<;i++)
{
num_12[i]=x%;
x=x/;
}
return num_12[]+num_12[]+num_12[]+num_12[];
}
int digits_16(int x)
{
int num_16[];
for(int i = ;i<;i++)
{
num_16[i]=x%;
x=x/;
}
return num_16[]+num_16[]+num_16[]+num_16[];
}
int main()
{ int num_16[];
int x = ;
for(int i=x;i<=;i++)
{
int sum = digits(i);
int sum_12 = digits_12(i);
int sum_16 = digits_16(i);
if(sum ==sum_12&&sum==sum_16)
{
cout<<i<<endl;
}
}
return ;
}

poj2196的更多相关文章

  1. 【POJ2196】Specialized Four-Digit Numbers(暴力打表)

    一道水题,只要会复制粘贴就好! #include <iostream> #include <cstring> #include <cstdlib> #include ...

随机推荐

  1. AngularJS 表单

    AngularJS 表单是输入控件的集合. HTML控件 以下 HTML input 元素被称为 HTML 控件: input 元素 select 元素 button 元素 textarea 元素 H ...

  2. Java学习手记2——多线程

    一.线程的概念 CPU执行程序,就好比一个人在干事情一样,同一个时间你只能做一件事情,但是这样的效率实在是太低了,在你用电脑的时候,听歌就不能浏览网页,看电影就不能下载视频,你想想是不是很蛋疼. 所以 ...

  3. redhat6&period;4上用apache建立os repos

    1.挂载OS介质文件 [root@server- Packages]# mkdir -p /media/dvd [root@server- Packages]# -20130130.0-Server- ...

  4. C语言宏高级用法 &lbrack;总结&rsqb;

    1.前言  今天看代码时候,遇到一些宏,之前没有见过,感觉挺新鲜.如是上网google一下,顺便总结一下,方便以后学习和运用.C语言程序中广泛的使用宏定义,采用关键字define进行定义,宏只是一种简 ...

  5. COJ 0802 非传统题(二)

    (颓了这么多天是时候干点正事了QAQ) 非传统题(二) 难度级别:B: 运行时间限制:1000ms: 运行空间限制:51200KB: 代码长度限制:2000000B 试题描述 还是很久很久以前,chx ...

  6. OCP-1Z0-051-题目解析-第5题

    5. Which SQL statements would display the value 1890.55 as $1,890.55? (Choose three .) A. SELECT TO_ ...

  7. hdu&lowbar;5507&lowbar;GT and strings&lpar;AC自动机&rpar;

    题目链接:hdu_5507_GT and strings 题意:给n个字符串和q个询问,每个询问给两个数字x,y,问1.x是否为y的子序列,2.x是否为y的子串,是输出1,否则输出0,每个询问输出2个 ...

  8. &lbrack;二&rsqb; JavaIO之File详解 以及FileSystem WinNTFileSystem简介

    File类 文件和目录路径名的抽象表示形式. 我们知道,对于不同的操作系统,文件路径的描述是不同的 比如 windows平台:用\ linux平台:用/   File是Java为了这一概念提供的抽象描 ...

  9. Angular基础&lpar;五&rpar; 内建指令和表单

    ​ Angular提供了一些内建的指令,可以作为属性添加给HTML元素,以动态控制其行为. 一.内建指令 a) *ngIf,可以根据条件来显示或隐藏HTML元素. <div *ngIf='a&g ...

  10. Java-Runoob-高级教程-实例-方法:13&period; Java 实例 – for 和 foreach循环使用

    ylbtech-Java-Runoob-高级教程-实例-方法:13. Java 实例 – for 和 foreach循环使用 1.返回顶部 1. Java 实例 - for 和 foreach循环使用 ...

相关文章