poj2196
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 7238 | Accepted: 5285 |
Description
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
Output
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
#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的更多相关文章
- 【POJ2196】Specialized Four-Digit Numbers(暴力打表)
一道水题,只要会复制粘贴就好! #include <iostream> #include <cstring> #include <cstdlib> #include ...
随机推荐
- Java实现一致性Hash算法深入研究
一致性Hash算法 关于一致性Hash算法,在我之前的博文中已经有多次提到了,MemCache超详细解读一文中”一致性Hash算法”部分,对于为什么要使用一致性Hash算法和一致性Hash算法的算法原 ...
- 合并多个excel工作簿
合并多个Excel工作簿,会出现电话号码以科学计数法显示,如果想要以字符串方式处理,要按如下完整代码 public static void mergeWorkBook() throws Excepti ...
- JavaScript闭包函数的写法
<script type="text/javascript"> //通过js内置的函数构造器创建函数 var func=new Function('a','b','re ...
- 解决方案--java执行cmd命令ProcessBuilder--出错Exception in thread "main" java.io.IOException: Cannot run program "dir d:\": CreateProcess error=2(xjl456852原创)
当我尝试在java中通过ProcessBuilder运行window的cmd命令时出现错误: public static void main(String [] args) throws IOExce ...
- 【git 问题小说说】 git add时候报错:LF will be replaced by CRLF
本文来自:http://blog.csdn.net/loovejava/article/details/22114477 最近工作在window平台,不怎么使用命令行了所以导致很多命令都不熟悉啦 哈哈 ...
- 一个提供jsp免费空间的站点
EATJ美国JSP虚拟主机商提供免费jsp空间申请,50M空间,每月3G的流量限制,支持Java5.0/6.0.PHP.CGI.Perl.SSI等,提供2个MySQL数据库,Tomcat v5.5/v ...
- 转载:android——eclipse如何去除Ctrl+shift+R组合键查找到的.class文件
转载自:http://blog.csdn.net/virgilli/article/details/22500409 AS里面的build文件下一堆的.class 文件,当你要定位资源文件的时候,有些 ...
- js 闭包和回调
原文:http://www.cnblogs.com/yuyuj/p/4525530.html 之前的工作都是基于老大搭建的框架,仿照他写的例子写的请求,很多东东也都做好了封装,只需要了解下直接调用就好 ...
- windows消息常量值
WM_NULL = 0WM_CREATE = 1应用程序创建一个窗口WM_DESTROY = 2一个窗口被销毁WM_MOVE = 3移动一个窗口WM_SIZE = 5改变一个窗口的大小WM_ACTIV ...
- GDI+ 颜色表示
一.GDI+中:Color位于System.Drawing命名空间下.当我们需要使用某种颜色时,我们可以用以下几种方式: ()Color.FromArgb(alpha, red, green, bl ...