(HDU)1197 -- Specialized Four-Digit Numbers(特殊四位数)

本文介绍了一个编程问题,即找出所有10进制、12进制及16进制下各位数字之和相等的四位数。通过枚举算法实现,并提供了完整的C++代码示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目链接:http://vjudge.net/problem/HDU-1197

找四位数中10进制、12进制、16进制表示各位数字和相同的数值。枚举即可:

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <cmath>
 4 #include <iostream>
 5 #include <algorithm>
 6 #include <string>
 7 #include <cstdlib>
 8 
 9 using namespace std;
10 
11 
12 int main()
13 {
14     int i,ans10,ans12,ans16,temp1,temp2,temp3;
15     for(i=2992;i<=9999;i++)
16     {
17         temp1=i;    temp2=i;    temp3=i;
18         ans10=0;    ans12=0;    ans16=0;
19         while(temp1)
20         {
21             ans10+=temp1%10;
22             temp1/=10;
23         }
24         while(temp2)
25         {
26             ans12+=temp2%12;
27             temp2/=12;
28         }
29         while(temp3)
30         {
31             ans16+=temp3%16;
32             temp3/=16;
33         }
34         if(ans10==ans12&&ans12==ans16)
35             printf("%d\n",i);
36     }
37     return 0;
38 }

 

转载于:https://www.cnblogs.com/ACDoge/p/6133030.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值