• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
dwtfukgv
博客园    首页    新随笔    联系   管理    订阅  订阅
HDU 1197 Specialized Four-Digit Numbers (枚举+进制转化,简单)

题意:让求从2992-9999中所有数字,满足10进制各位之和和12进制和16进制各位数字之和相等。

析:没啥可说的,只能枚举从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;
}

 

posted on 2016-06-02 17:57  dwtfukgv  阅读(191)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3