黑洞数
int 数重组位最大(int 整数) { /*C++任意输入一个整数,再把它的各位数字重新组合一个新的整数,使其值最大*///缘由https://bbs.bccn.net/viewthread.php?tid=499134&pid=2718301&page=1#pid2718301 int 输入整数 = 整数, 数(0), 输出(0), 取值(0), 比较(0), 暂存(0), 位(0), 序(0), 反向(0); bool 控制(true); if (输入整数 < 100)输入整数 *= 10; if (输入整数 > 1000)输入整数 /= 10; //scanf_s("%d", &输入整数); do { 比较 = 序 = 0; 暂存 = 输入整数; do { 取值 = 暂存 % 10; if (取值 > 比较)/*每次取最大值*/ { 比较 = 取值; 数 = 序; } ++序; } while (暂存 /= 10); if (控制) 位 = 反向 = 序; 输出 += 比较 * pow(10, --位); 控制 = false; } while (输入整数 -= 比较 * pow(10, 数));/*每次减去最大值*/ //printf_s("%d ", 输出); 数 = 0; 取值 = 输出; do { 数 += (输出 % 10) * pow(10, --反向); } while (输出 /= 10);/*反向输出各位数*/ //printf_s("%d ", 数); cout << 取值 << "-" << 数 << "=" << 取值 - 数 << endl; return 取值 - 数; }
int shu = 44; cout << "输入二或三位数:"; cin >> shu; while((shu=数重组位最大(shu))!=495);
int shu = 3112344, shuan = shu, p = 0, j = 0, cf[77]{0}; while (++shu < INT_MAX) { j = p = 0; while (shuan = 数重组值最大小(shuan))if (shuan) { p = 77; while (cf[--p]); if(cf[p] == shuan)break; cout << shu << ":" << shuan << ends; system("pause"); } else { while (cf[j]) if (cf[j] == shuan) { cout << "黑洞数:" << shuan << ends; p = 77; while (cf[--p]); cf[p] = shuan; system("pause"); } else ++j; cf[j++] = shuan; } while (j-- >= 0)cf[j] = 0; shuan = ++shu; cout << endl; }
原创文章,作者:xianfajushi的博客,如若转载,请注明出处:https://www.zengqueling.com/%e9%bb%91%e6%b4%9e%e6%95%b0/