标签:names scanf stream ace while break min span ret
#include<cstdio> #include<algorithm> #include<iostream> using namespace std; int num[5]={0}; bool cmpa(int a,int b) { return a < b; } bool cmpd(int a,int b) { return a > b; } void to_array(int n,int num[]) { for(int i=0;i<4;i++) { num[i] = n%10; n /=10; } } int to_number(int num[]) { int temp=0; for(int i=0;i<4;i++) temp = temp*10+num[i]; return temp; } int main() { int n; scanf("%d",&n); while(1) { to_array(n,num); sort(num,num+4,cmpd); int max = to_number(num); sort(num,num+4,cmpa); int min = to_number(num); n = max - min; printf("%d-%d=%d\n",max,min,n); if(!n || n==6174)break; } return 0; }
Kaprekar数学黑洞
标签:names scanf stream ace while break min span ret
原文地址:https://www.cnblogs.com/xhjj/p/12228817.html