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

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

1069. The Black Hole of Numbers (20)

2019-11-11 06:35:17
字體:
來源:轉載
供稿:網友

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;}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 亚洲白嫩在线观看 | 亚洲国产精品二区 | 国产超碰人人爽人人做人人爱 | 欧美一级性 | 亚洲精久| 日韩视频―中文字幕 | 懂色av懂色aⅴ精彩av | 无遮挡一级毛片视频 | 精品亚洲va在线va天堂资源站 | 性欧美性欧美 | 国内精品久久久久久2021浪潮 | 国产成人在线看 | 136福利视频 | 正在播放91 | 精品国产一级毛片 | 欧美女同hd | 国产成人强伦免费视频网站 | 国内精品久久久久久影视8 嫩草影院在线观看网站成人 | 一级做受毛片免费大片 | 日韩午夜一区二区三区 | 久久精品re| 久久久久久久久久91 | 亚洲国产美女视频 | 色婷婷一区二区三区 | 久久久久女人精品毛片九一 | 91久久久久久久一区二区 | 国产精品91在线 | 狠狠操人人干 | 国产精品嘿咻嘿咻在线播放 | 久久美女色视频 | 欧美一级毛片免费观看视频 | 北原夏美av | 日日噜噜噜夜夜狠狠久久蜜桃 | 精品一区二区三区日本 | 国产日本欧美在线观看 | 国产精品久久久久久影院8一贰佰 | 国产一级毛片高清 | 久久精品中文字幕一区二区 | 国产色视频一区 | 欧美 国产 综合 | 性欧美xxxx免费岛国不卡电影 |