当前位置:网站首页>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 6174
As difference occurs, see example for output format.Note that each number is output as 4
digits.
Input Sample 1:
6767
Output Sample 1:
7766 - 6677 = 10899810 - 0189 = 96219621 - 1269 = 83528532 - 2358 = 6174
Input Sample 2:
2222
Output 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 <
边栏推荐
- Excuse me if you want to write data in mysql, with flink - connector - JDBC directly is ok, but I'm in the f
- PAT乙级-B1019 数字黑洞(20)
- Happens-before rules for threads
- 让硬盘更快,让系统更稳定
- js 图形操作一(兼容pc、移动端实现 draggable属性 拖放效果)
- tensorflow.keras无法引入layers
- 线程之Happens-before规则
- leetcode refers to Offer 10- II. Frog jumping steps
- express hot-reload
- The Coolest Kubernetes Network Solution Cilium Getting Started Tutorial
猜你喜欢
放大器OPA855的噪声计算实例
Creo 9.0 基准特征:基准平面
【Excel实战】--图表联动demo_001
There is only one switch, how to realize the nqa of master-slave automatic switching
How to make pictures clear in ps, self-study ps software photoshop2022, simple and fast use ps to make photos clearer and more textured
嵌入式实操----基于RT1170 移植memtester做SDRAM测试(二十五)
MySQL内部函数介绍
sql server中 两表查询 平均数 分组
复现一次循环和两次循环
Code Audit - PHP
随机推荐
express hot-reload
The difference between beautiful MM and ordinary MM
国际原子能机构总干事称乌克兰扎波罗热核电站安全形势堪忧
全面讲解GET 和 POST请求的本质区别是什么?原来我一直理解错了
Happens-before rules for threads
深度学习21天——卷积神经网络(CNN):服装图像分类(第3天)
Luogu P4588: [TJOI2018]数学计算
The Secrets of the Six-Year Team Leader | The Eight Most Important Soft Skills of Programmers
Is there a problem with writing this?How to synchronize data in sql-client
按钮上显示值的轮流切换
Embedded practice ---- based on RT1170 transplant memtester to do SDRAM test (25)
【Excel实战】--图表联动demo_001
Luogu P3368: 【模板】树状数组 2
love is a sad song
Hundred lines of code launch red hearts, why programmers lose their girlfriends!
汇编语言(8)x86内联汇编
Example of Noise Calculation for Amplifier OPA855
哪个是你爱情的颜色?
施一公:科学需要想象,想象来自阅读
工程制图直线投影练习