当前位置:网站首页>PAT Class B-B1019 Digital Black Hole (20)
PAT Class B-B1019 Digital Black Hole (20)
2022-08-05 09:13:00 【nekoha_dexter】
Given any 4-digit positive integer whose digits are not exactly the same, if we first sort the 4 numbers non-increasingly, then non-decreasingly, and then subtract the 2nd number from the 1st number, we will geta new number.Keep doing this over and over again, and we'll soon stop at 6174 known as the "digital black hole", the magic number also known as the Kaprekar constant.
For example, if we start with 6767, we will get
7766 - 6677 = 10899810 - 0189 = 96219621 - 1269 = 83528532 - 2358 = 61747641 - 1467 = 6174 …Given any 4-digit positive integer, write a program to demonstrate the process of reaching a black hole.
input format:
The input gives a positive integer N in the interval (0,104).
Output format:
If all 4 digits of N are equal, output N - N = 0000 on one line; otherwise, output each step of the calculation on one line until 6174As difference occurs, see example for output format.Note that each number is output as 4 digits.
Input Sample 1:
6767Output Sample 1:
7766 - 6677 = 10899810 - 0189 = 96219621 - 1269 = 83528532 - 2358 = 6174Input Sample 2:
2222Output Sample 2:
2222 - 2222 = 0000#include#includeusing namespace std;string s1,s2;int main(){cin >> s1;int ans;//s1 may be less than 4 digits, 0 should be inserteds1.insert(0,4-s1.size(),'0');do{sort(s1.begin(), s1.end());s2 = s1;//s1 is from big to small at this timereverse(s1.begin(), s1.end());cout < 边栏推荐
- Comprehensively explain what is the essential difference between GET and POST requests?Turns out I always misunderstood
- 并发之CAS
- The color of life divine
- selectPage 动态改变参数方法
- 使用 External Secrets Operator 安全管理 Kubernetes Secrets
- 【LeetCode】623. Add a row to the binary tree
- 网页直接访问链接不让安全中心拦截
- leetcode 剑指 Offer 10- I. 斐波那契数列
- CVPR 2022 | 将X光图片用于垃圾分割,港中大(深圳)探索大规模智能垃圾分类
- Undefined symbols for architecture arm64解决方案
猜你喜欢

深度学习21天——卷积神经网络(CNN):天气识别(第5天)

Creo 9.0 基准特征:基准平面

工程制图知识点

ECCV 2022 Oral Video Instance Segmentation New SOTA: SeqFormer & IDOL and CVPR 2022 Video Instance Segmentation Competition Champion Scheme...

Detailed explanation of DNS query principle

sql server收缩日志的作业和记录,失败就是因为和备份冲突了吗?

欧盟 | 地平线 2020 ENSEMBLE:D2.13 SOTIF Safety Concept(上)

使用 External Secrets Operator 安全管理 Kubernetes Secrets

ECCV 2022 Oral 视频实例分割新SOTA:SeqFormer&IDOL及CVPR 2022 视频实例分割竞赛冠军方案...

工程制图试题
随机推荐
Luogu: P2574 XOR的艺术 [线段树]
15.1.1、md—md的基础语法,快速的写文本备忘录
egg framework
16种香饭做法全攻略
k-nearest neighbor fault monitoring based on multi-block information extraction and Mahalanobis distance
【零基础玩转BLDC系列】无刷直流电机无位置传感器三段式启动法详细介绍及代码分享
2022.8.3
Luogu P1908: 逆序对 [树状数组]
MySQL内部函数介绍
七夕给自己new一个chatRobot当对象
C语言-数组
使用HBuilder离线本地打包ipa教程
微信小程序请求封装
CCVR eases heterogeneous federated learning based on classifier calibration
tensorflow.keras无法引入layers
哪个是你爱情的颜色?
IT研发/开发流程规范效能的思考总结
Linux导出数据库数据到硬盘
Undefined symbols for architecture arm64解决方案
【Excel实战】--图表联动demo_001