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

首頁 > 學院 > 開發設計 > 正文

1069. The Black Hole of Numbers (20)

2019-11-11 04:34:10
字體:
來源:轉載
供稿:網友

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;}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: xxxxxx打针视频vk | 亚洲第一精品在线 | 免费一区区三区四区 | 久久国产精品二国产精品中国洋人 | 国产精品高潮视频 | 久久综合久久美利坚合众国 | gril hd| 精品亚洲免费 | 色人阁五月天 | 成人店女老板视频在线看 | 欧美在线中文字幕 | 法国性xxx精品hd | 成人一级视频在线观看 | 中文字幕在线视频网站 | 欧美精品一区二区久久 | 国产91九色视频 | 欧美性生交大片 | 精品国产一二区 | 在线视频观看国产 | 亚洲国产色婷婷 | 久久国产28 | 久草视频在线看 | 日韩精品99久久久久久 | 久久国产秒 | 亚洲最大av网站 | 成年免费在线视频 | 亚洲午夜影院在线观看 | 欧美精品在线免费观看 | av在线播放网址 | 在线播放中文 | 久久精品视频2 | 久久久久久久久国产 | 一级毛片在线免费观看视频 | 欧美特黄a | 韩国19禁在线 | 黄色片免费在线播放 | 亚洲码无人客一区二区三区 | 国产喷白浆10p | 国产精品久久久久一区二区 | 久久久久久久久国产 | 日韩毛片免费观看 |