D - Specialized Four-Digit Numbers
Description
Input
Output
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的更多相关文章
- [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 ...
- 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 ...
- 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'}. ...
- [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 ...
- 利用Python【Orange】结合DNA序列进行人种预测
http://blog.csdn.net/jj12345jj198999/article/details/8951120 coursera上 web intelligence and big data ...
- PAT/进制转换习题集
B1022. D进制的A+B (20) Description: 输入两个非负10进制整数A和B(<=230-1),输出A+B的D (1 < D <= 10)进制数. Input: ...
- [转]http://lua-users.org/wiki/LpegTutorial
Simple Matching LPeg is a powerful notation for matching text data, which is more capable than Lua s ...
- FZU 2215 Simple Polynomial Problem(简单多项式问题)
Description 题目描述 You are given an polynomial of x consisting of only addition marks, multiplication ...
- Problem K 栈
Description A math instructor is too lazy to grade a question in the exam papers in which students a ...
- PAT 1019
1019. General Palindromic Number (20) A number that will be the same when it is written forwards or ...
随机推荐
- iOS archive(归档)的总结
http://www.cnblogs.com/ios8/p/ios-archive.html
- ios 获取屏幕的属性
屏幕尺寸 CGRect screen = [UIscreen mainScreen].bounds 状态栏尺寸 CGRect rect = [[UIApplication sharedApp ...
- 6、Khala的登录生命周期管理
khala能够对设备进行生命周期管理,并提供了与生命周期相关的接口,用户只需在具体的设备类型实现类中重写这些生命周期接口,即可享受khala对于生命周期管理的同时定制与业务相关的操作.具体接口解释如下 ...
- OpenCV——Haar-like特征
Haar-like特征--即Haar特征,是计算机视觉领域一种常用的特征描述算子.它最早用于人脸描述. 目前常用的Haar-like特征可以分为以下几类:线性特征.边缘特征.点特征(中心特征).对角线 ...
- C++程序设计实践指导1.15找出回文数改写要求实现
改写要求1:用单链表实现 #include <cstdlib> #include <iostream> using namespace std; struct LinkNode ...
- Tomcat学习笔记 - 错误日志 - Tomcat安装版安装后第二次启动后闪退(转)-- javac不是内部或外部命令 -- 配置java环境教程
如果安装成功并且安装完成第一次启动是成功的,第二次就闪退的话,原因之一是没有配置java的环境.在网上找的配制方法有很多错误,测试javac命令时候会提示不是内部或外部命令,找到一个正确的教程.如下, ...
- bootstrap模态框垂直居中
很久没有写东西了,之前想写一些移动端的东西以后补上吧,移动端发展还是蛮快的,回正题. 因为最近在弄一个系统,系统中引用了bootstrap,发现模态框垂直不居中,遂搜索了一下,也都试了一下,无非都是在 ...
- WSGI的理解
Python web开发中,服务端程序可分为2个部分: 服务器程序(用来接收.整理客户端发送的请求) 应用程序(处理服务器程序传递过来的请求) 在开发应用程序的时候,我们会把常用的功能封装起来,成为各 ...
- Html 编码 queryUrl = encodeURI(queryUrl);
Html 编码 queryUrl = encodeURI(queryUrl);
- c#实现生产者消费者模式
; } Environment.ExitCode = result; } }}