黑洞数二(代码很少)

此代码的产生,是和一个网友比代码短而产生的。

 1 #include<stdio.h>
 2 #include<string.h>
 3 #include<stdlib.h>
 4 int a[90000][10]={0},b[90000][10]={0};
 5 char c[100000]={0},str[6]="";
 6 int sort(int num)
 7 {
 8     itoa(num,str,10);
 9     for(int i=0;i<4;i++)
10         for(int j=i;j<5;j++)
11             if(str[i]<str[j])
12                 {char c=str[i];str[i]=str[j];str[j]=c;}
13     return atoi(str);
14 }
15 int main()
16 {
17     for(int i=10001;i<=99999;i++)
18     {     
19         for(int j=0,num=i;j<10;j++)
20             a[i-10000][j]=num=sort(num)-atoi(strrev(str));//欲形成循环圈
21         int j=0;
22         for(;j<10;j++)//找出循环圈
23         {
24             if(a[i-10000][9-j]==b[i-10000][0]) break;
25             b[i-10000][j]=a[i-10000][9-j];
26             if(c[b[i-10000][j]]||a[i-10000][9-j]<10000)break; 
27             else c[b[i-10000][j]]=1;
28             printf("%-6d",b[i-10000][j]);
29         }
30         if(j>1)printf("\n");
31     }
32     getchar();
33     return 0;
34 }

原文地址:https://www.cnblogs.com/dzqdzq/p/3057108.html