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

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

1069. The Black Hole of Numbers (20)

2019-11-11 05:04:42
字體:
供稿:網(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ā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 天天撸日日夜夜 | 免费a视频在线观看 | 欧美成人精品欧美一级 | 九九热在线视频观看这里只有精品 | 国产一区二区三区黄 | 91精品动漫在线观看 | 蜜桃成品人免费视频 | 欧美不卡| 精品国产一区二区三区久久久 | 久久国产中文字幕 | 欧美一级黄色网 | 亚洲骚综合 | 玩偶姐姐在线观看免费 | 国产毛片aaa一区二区三区视频 | 久久精品.com | 91精品国产777在线观看 | 黄色高清免费 | av91肉丝一区二区电影 | 国产精品成人久久久久a级 av电影在线免费 | 天天操天天碰 | 国产日产精品一区四区介绍 | 特黄一级小说 | 久久久精品视频免费看 | 欧美成人精品一区二区 | 国产成年人视频网站 | 成人免费观看毛片 | 国产99久久久国产精品 | 免费视频www在线观看 | 在线天堂中文在线资源网 | 免费一级毛片网站 | 黄色男女视频 | 免费观看的毛片手机视频 | 欧美一级做性受免费大片免费 | 久久成年网站 | 国产亚洲精品久久久久5区 日韩一级片一区二区三区 国产精品久久久久av | 久久成人免费观看 | 精品久久久久久成人av | av在线影片 | 精品一区二区久久久久久按摩 | 日韩视频一二区 | 亚洲一区二区网址 |