PTA——黑洞数

我的程序,一个用例通不过

 #include<stdio.h>
void sort(int *a,int n); int main() {
int num,a,b,c,count=;
scanf("%d",&num);
while(num!=&&num!=) {
a = num/;
b = num%/;
c = num%%;
int p[] = {a,b,c};
sort(p,);
int g1,g2;
g1 = *p[]+*p[]+p[];
g2 = *p[]+*p[]+p[];
num = g1-g2;
printf("%d: %d - %d = %d\n",count,g1,g2,num);
count++;
}
} void sort(int *a,int n) {
int i, j, t;
for (i = ; i < n; i++) {
t = a[i];
j = i - ;
while (j >= && t > a[j]) {
a[j+] = a[j];
j--;
}
a[j+] = t;
}
}

网友的程序,更加简洁:

 #include <stdio.h>
int main(){
int n,max,min,f=,a,b,c,t;
scanf("%d",&n);
while(n!=||f==){
a=n/;b=n/%;c=n%;
if (a<b){
t = a;
a = b;
b = t;
}
if (a<c){
t = a;
a = c;
c = t;
}
if (b<c){
t = b;
b = c;
c = t;
}
max = a*+b*+c;
min = c*+b*+a;
n = max - min;
f++;
printf("%d: %d - %d = %d\n",f,max,min,n);
} return ;
}
上一篇:【MySQL】Error 1264: out of range value for column


下一篇:Vuejs中slot实现自定义组件header、footer等