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 ...
随机推荐
- break,continue,return 区别
using System;using System.Collections.Generic;using System.Text; namespace breakcontinue_test{ cl ...
- (转)Should I use char** argv or char* argv[]
As you are just learning C, i recommend you to really try to understand the differences between ar ...
- (原)caffe中通过图像生成lmdb格式的数据
转载请注明出处: http://www.cnblogs.com/darkknightzh/p/5909121.html 参考网址: http://www.cnblogs.com/wangxiaocvp ...
- Object.create函数
创建一个具有指定原型且可选择性地包含指定属性的对象. Object.create(prototype, descriptors) 参数 prototype必需. 要用作原型的对象. 可为 null. ...
- linux下python3连接mysql数据库
python语言的3.x完全不向前兼容,导致我们在python2.x中可以正常使用的库,到了python3就用不了了.比如说mysqldb 1.安装pymysql pymysql就是作为python3 ...
- 使导出excle文档实现ALT+Enter的效果()
JAVA中输入什么转义字符,使导出excle文档实现ALT+Enter的效果?或者有没有其他方法可以实现. 20 JAVA中输入什么转义字符,使导出excle文档实现ALT+Enter的效果?或者有没 ...
- 典型的DIV CSS三行二列居中高度自适应布局
如何使整个页面内容居中,如何使高度适应内容自动伸缩.这是学习CSS布局最常见的问题.下面就给出一个实际的例子,并详细解释.(本文的经验和是蓝色理想论坛xpoint.guoshuang共同讨论得出的.) ...
- SQL Server 2008空间数据应用系列二:空间索引(Spatial Index)基础
原文:SQL Server 2008空间数据应用系列二:空间索引(Spatial Index)基础 在前一篇博文中我们学习到了一些关于地理信息的基础知识,也学习了空间参照系统,既地球椭球体.基准.本初 ...
- Windows 7下可以使用的各个命令语句+C#打开
Windows 7下可以使用的各个命令语句: control.exe /name microsoft.folderoptions 启动资源管理器的 文件夹属性 选项卡 control.exe /n ...
- kabina启动配置
启动 kibana # /usr/local/kibana-4.1.1-linux-x64/bin/kibana zjtest7-redis:/usr/local/kibana-4.5.3-linux ...