HDU 1197 Specialized Four-Digit Numbers (枚举+进制转化,简单)
2016-06-02 17:57
330 查看
题意:让求从2992-9999中所有数字,满足10进制各位之和和12进制和16进制各位数字之和相等。
析:没啥可说的,只能枚举从2992-9999,每个进制都算一下。
代码如下:
析:没啥可说的,只能枚举从2992-9999,每个进制都算一下。
代码如下:
#include <iostream> #include <cstdio> #include <algorithm> #include <queue> #include <vector> #include <cstring> #include <map> using namespace std; const int maxn = 70; int itoa_n(int n, int r){ int ans = 0; while(n){ ans += n % r; n /= r; } return ans; } int main(){ for(int i = 2992; i < 10000; ++i){ if(itoa_n(i, 10) == itoa_n(i, 12) && itoa_n(i, 10) == itoa_n(i, 16)) printf("%d\n", i); } return 0; }
相关文章推荐
- 点击图片产生水波的动画效果代码展示
- 设置QPushButton的平面与突出(遍历控件)
- 第二阶段团队项目冲刺第十天
- android开发笔记之网络编程—使用TCP协议和URL进行网络编程
- bitmap格式分析
- 类与对象及继承多态
- Struct和Class的区别
- Powershell学习之道-文件夹共享及磁盘映射
- 对某APP的逆向之旅(1)
- 指针数组和数组指针
- 第9周课后实践 阅读程序,请写出这些程序的运行结果(1)
- activity切换动画 右边进入右边出
- 监听和通知
- POJ 1493(水题)
- spring boot 学习之controller
- homebrew + item + zsh 整合
- C++中#include的工作原理
- 为类模板加上构造函数和默认构造函数
- javabean的简单总结
- aop 环绕通知 可以计算机 程序执行的时间