标签:can some log break skill nbsp using algorithm ++
#include<cstdio> #include<algorithm> using namespace std; bool cmp1(int a, int b) { return a>b;//sorted by decreasing } bool cmp2(int a, int b) { return a<b;//sorted by decreasing } void to_array(int n, int arr[]) { for (int i = 0; i<4; i++) { arr[i] = n % 10;//this is a skill n = n / 10; } } int to_number(int arr[]) { int sum = 0; for (int i = 0; i<4; i++) { sum = sum * 10 + arr[i];//this is a skill } return sum; } int main() { int n; int max, min; int num[5]; scanf("%d",&n); while (1)//a way always do something { to_array(n, num); sort(num, num + 4, cmp1);//its great, meet your need, can up and down max = to_number(num); sort(num, num + 4, cmp2); min = to_number(num); n = max - min; printf("%04d - %04d = %04d\n", max, min, n); if (n == 0 || n == 6174) break; } return 0; }
标签:can some log break skill nbsp using algorithm ++
原文地址:http://www.cnblogs.com/dusanlang/p/7648162.html