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 ...
随机推荐
- OpenCV——无法启动此程序,丢失**解决办法
OpenCV程序运行时,有时出现以下错误: 解决方法: 在opencv安装目录下找到这个链接库,将其复制到以下指定目录中 我的链接库目录为:E:\Program files\opencv\build\ ...
- (原)Ubuntu14中安装GraphicsMagick
转载请注明出处: http://www.cnblogs.com/darkknightzh/p/5661439.html 参考网址: http://comments.gmane.org/gmane.co ...
- Linux安装系统注意事项及系统初始化
Linux安装系统注意事项 1.分区 学习用途: /boot:200M /swap :内存的1到2倍 /:根据需要分配大小,比如虚拟机下总空间是15G,那么可以分配8——10G跟/分区,如果是生产 ...
- jQuery模拟瀑布流布局
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- FloatingActionButton 完全解析[Design Support Library(2)]
一.简单使用 布局: <android.support.design.widget.FloatingActionButton android:layout_width="wrap_co ...
- php word转HTML
因为安装的的xampp不知道如何查看我的Apache版本是多少,就先把com.allow_dcom=true打开了,但是仍旧报错说找不到com类,然后就把下面的extension扩展添加到php.in ...
- 超级密码(dfs)
超级密码233 Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total S ...
- MVC4商城项目四:应用Bundle捆绑压缩技术
从MVC4开始,我们就发现,项目中对Global.asax进行了优化,将原来在MVC3中使用的代码移到了[App_Start]文件夹下,而Global.asax只负责初始化.其中的BundleConf ...
- 纯js实现积木(div)拖动效果
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- WPF 资源收集
转载地址:http://www.cnblogs.com/zhoujg/archive/2009/11/04/1596195.html OpenExpressApp的UI现在是使用WPF,所以熟悉WPF ...