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

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

1069. The Black Hole of Numbers (20)

2019-11-11 05:07:46
字體:
來源:轉載
供稿:網友

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;}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 欧美一级毛片免费观看视频 | 狠狠色噜噜狠狠狠米奇9999 | 欧美在线观看黄色 | 日韩一级片一区二区三区 | 色av综合在线 | 成人短视频在线观看 | av在线看网站 | 精品一区二区三区中文字幕老牛 | 成年人网站视频免费 | 成人免费观看49www在线观看 | 91九色视频观看 | 1024亚洲天堂 | 国产精品91久久久 | 99综合视频 | 成人午夜视频网站 | 在线看一级片 | 欧美在线成人影院 | 国产精品久久久久久久久久久久久久久 | 黄色免费在线视频网站 | 911视频免费版 | 99激情视频| 中文在线观看www | 国产精品成人一区 | 日韩激情一区 | 黄色大片在线观看 | 中文欧美日韩 | 超碰97最新 | 久久精品视频亚洲 | 国产在线免费 | 日韩一级精品 | 一级黄色在线观看 | 成熟女人特级毛片www免费 | 国产精品av久久久久久久久久 | 久久99国产精品免费网站 | hdhdhdhd19日本人| 精品国产一区二 | 操碰| 成人一级视频 | 欧美精品免费一区二区三区 | 一区二区三区视频在线播放 | 久久噜噜噜 |