麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

1069. The Black Hole of Numbers (20)

2019-11-11 05:43:08
字體:
供稿:網(wǎng)友

For any 4-digit integer except the ones with all the digits being the same, if we sort the digits in non-increasing order first, and then in non-decreasing order, a new number can be obtained by taking the second number from the first one. Repeat in this manner we will soon end up at the number 6174 – the “black hole” of 4-digit numbers. This number is named KaPRekar Constant.

For example, start from 6767, we’ll get:

7766 - 6677 = 1089 9810 - 0189 = 9621 9621 - 1269 = 8352 8532 - 2358 = 6174 7641 - 1467 = 6174 … …

Given any 4-digit number, you are supposed to illustrate the way it gets into the black hole.

Input Specification:

Each input file contains one test case which gives a positive integer N in the range (0, 10000).

Output Specification:

If all the 4 digits of N are the same, print in one line the equation “N - N = 0000”. Else print each step of calculation in a line until 6174 comes out as the difference. All the numbers must be printed as 4-digit numbers.

Sample Input 1: 6767 Sample Output 1: 7766 - 6677 = 1089 9810 - 0189 = 9621 9621 - 1269 = 8352 8532 - 2358 = 6174 Sample Input 2: 2222 Sample Output 2: 2222 - 2222 = 0000

#include<cstdio>#include<algorithm>using namespace std;bool cmp(int a,int b){ return a>b;}void toArray(int a,int b[]){ int mask=1000; for(int i=0;i<4;i++){ b[i]=a/mask; a%=mask; mask/=10; }}int toNum(int a[]){ int ans=0; for(int i=0;i<4;i++){ ans=ans*10+a[i]; } return ans;}int main(){ int a; scanf("%d",&a); int num[5],min,max; do{ toArray(a,num); sort(num,num+4); min=toNum(num); sort(num,num+4,cmp); max=toNum(num); a=max-min; printf("%04d - %04d = %04d/n",max,min,a); }while(a!=0&&a!=6174); return 0;}
發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 欧美激情天堂 | 欧美成人精品一区二区三区 | 日韩一级成人 | 一级空姐毛片 | 成人在线视频黄色 | 成人三级黄色片 | 国产超碰人人爽人人做人人爱 | 国产电影精品久久 | 免费在线国产 | a黄在线观看 | 黄在线观看在线播放720p | 亚洲天堂中文字幕在线观看 | 久久久免费观看完整版 | 欧美国产日韩在线观看成人 | 国产羞羞视频在线观看 | 欧美精品在线视频观看 | 中韩毛片 | 亚洲欧美日韩免费 | 黄色香蕉视频 | 国产一区二区免费在线观看 | 亚洲午夜1000理论片aa | 性欧美性欧美 | 好吊色欧美一区二区三区四区 | 久久久综合视频 | 亚洲特黄妇女高潮 | 久久精品一区二区三区国产主播 | 免费视频一区 | 草逼一区 | av在线免费播放网站 | 成人勉费视频 | 国产精品视频导航 | 亚洲天堂字幕 | 欧美人与禽性xxxxx杂性 | 国产18视频 | 日本在线免费观看视频 | 精品一区二区三区在线观看国产 | 国产亚洲综合精品 | 双性精h调教灌尿打屁股的文案 | 91情侣偷在线精品国产 | 久久狠狠高潮亚洲精品 | 黄色三级三级三级 |