HDOJ 1197 Specialized Four-Digit Numbers

【题意】:输出四位数中所有十进制=十二进制=十六进制的数。

【思路】:穷举就OK。避免重复可以再函数中增加一个位数的参数,这样三个函数写一个就行。

【AC代码】:

#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iomanip>
using namespace std;

int getDec(int x)
{
    int sum = 0;
    while (x)
    {
        sum += x%10;
        x /= 10;
    }
    return sum;
}

int getDuo(int x)
{
    int sum = 0;
    while (x)
    {
        sum += x%12;
        x /= 12;
    }
    return sum;
}

int getHex(int x)
{
    int sum = 0;
    while (x)
    {
        sum += x%16;
        x /= 16;
    }
    return sum;
}

int main()
{
    int i = 0;
    for (i = 1000; i <= 9999; i++)
    {
        if (getDec(i) == getDuo(i) && getHex(i) == getDuo(i))
            cout << i << endl;
    }
    return 0;
}
时间: 2024-10-08 15:46:22

HDOJ 1197 Specialized Four-Digit Numbers的相关文章

Hdu 1197 Specialized Four-Digit Numbers

Specialized Four-Digit Numbers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 7038    Accepted Submission(s): 5148 Problem Description Find and list all four-digit numbers in decimal notation t

杭电 HDU 1197 Specialized Four-Digit Numbers

Specialized Four-Digit Numbers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 4603    Accepted Submission(s): 3344 Problem Description Find and list all four-digit numbers in decimal notation

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

hdoj 2817 A sequence of numbers【快速幂】

A sequence of numbers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4384    Accepted Submission(s): 1374 Problem Description Xinlv wrote some sequences on the paper a long time ago, they might

HDOJ 2817 A sequence of numbers【快速幂取模】

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2817 A sequence of numbers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3754    Accepted Submission(s): 1152 Problem Description Xinlv wrote so

hdoj 2817 A sequence of numbers(快速幂取模)

A sequence of numbers http://acm.hdu.edu.cn/showproblem.php?pid=2817 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 4046    Accepted Submission(s): 1242 Problem Description Xinlv wrote some se

Pattern类(java JDK源码记录)

1 /* 2 * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved. 3 * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. 4 * 5 * 6 * 7 * 8 * 9 * 10 * 11 * 12 * 13 * 14 * 15 * 16 * 17 * 18 * 19 * 20 * 21 * 22 * 23 *

grep Demo

最近在学习Linux的几个非常强大的命令awk, sed, grep. 之前对这些命令只是有非常皮毛的了解. 最近稍微深入的对这些命令进行一些学习.sed的主要功能如下: @1: 正则匹配某个字符串. @2: grep具备递归搜索文件/目录功能. #!/bin/bash #File: grepDemo.sh #Author: lxw #Time: 2014-08-21 #Usage: Demonstration for grep. main(){ #The following 2 lines a

[转]http://lua-users.org/wiki/LpegTutorial

Simple Matching LPeg is a powerful notation for matching text data, which is more capable than Lua string patterns and standard regular expressions. However, like any language you need to know the basic words and how to combine them. The best way to