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 ...
随机推荐
- c语言局部变量 静态局部变量 全局变量与静态全局变量
基本概念: 作用域:起作用的区域,也就是可以工作的范围. 代码块:所谓代码块,就是用{}括起来的一段代码. 数据段:数据段存的是数,像全局变量就是存在数据段的 代码段:存的是程序代码,一般是只读的. ...
- Spring 的优秀工具类盘点第 1 部分
文件资源操作 文件资源的操作是应用程序中常见的功能,如当上传一个文件后将其保存在特定目录下,从指定地址加载一个配置文件等等.我们一般使用 JDK 的 I/O 处理类完成这些操作,但对于一般的应用程序来 ...
- php_mysql、php_mysqli 与 pdo_mysql 的区别与选择
php与mysql的连接有三种API接口,分别是:PHP的MySQL扩展 .PHP的mysqli扩展 .PHP数据对象(PDO) ,下面针对以上三种连接方式做下总结,以备在不同场景下选出最优方案. ...
- JavaScript 获取CSS媒体查询信息
var result = window.matchMedia('(max-width: 700px)'); if (result.matches) { console.log('页面宽度小于等于700 ...
- Eclipse中Cannot find any provider supporting DES解决之道
原文出处:http://blog.csdn.net/darwinchina/article/details/12037999 异常: Caused by: java.security.NoSuchAl ...
- 网络测试工具netperf
Netperf是一种网络性能的测量工具,主要针对基于TCP或UDP的传输.Netperf根据应用的不同,可以进行不同模式的网络性能测试,即批量数据传输(bulk data transfer)模式和请求 ...
- vim的用法
1. vi 与 vim 有什么区别呢,它们之间有什么关系?Vim是从Vi发展出来的一个文本编辑器,可以看作是vi的升级版.Vim的主要功能与原始的Vi完全兼容,vi不会显示颜色,而vim会根据文件内容 ...
- sql 2000 分页
create PROCEDURE [dbo].[Proc_GetPageList] ( @Tables varchar(1000), --表名 @PK varchar(100 ...
- struts2 MessageStoreInterceptor 拦截器的使用
MessageStoreInterceptor 拦截器可以把和该 Action 相关的 messages, errors 和 field errors(下称 "消息") 保存到 s ...
- C#传值
C#若不加限制传值时自带的类型为值传递,自创的类型为引用传递 using System; using System.Collections.Generic; using System.Linq; us ...