Algorithm

枚举

image-20240301155400055

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//
// Created by sunny on 24.03.01.
//
#include <stdio.h>
int main(){
for (int a = 0; a < 10; ++a) {
for (int b = 0; b < 10; ++b) {
for (int c = 0; c < 10; ++c) {
if(a*100+b*10+c+b*100+c*10+c==532){
printf("%d %d %d",a,b,c);
}
}
}
}
}

image-20240302144945929

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
//
// Created by sunny on 24.03.02.
//
#include "stdio.h"
int main(){
for (int a = 0; a < 10; ++a) {
for (int b = 0; b <10 ; ++b) {
for (int c = 0; c < 10; ++c) {
for (int d = 0; d < 10; ++d) {
if((a*1000+b*100+c*10+d)*9==(d*1000+c*100+b*10+a))
printf("%d %d %d %d\n",a,b,c,d);
}
}
}
}
}

image-20240302145553655

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
//
// Created by sunny on 24.03.02.
//
#include "stdio.h"
int isreserves(int sum);
int main(){
for (int i = 0; i < 256; ++i) {
int sum=i*i;
int reserves=isreserves(sum);
if(i*i==reserves)
printf("%d的平方为%d,他的逆序数是%d\n",i,i*i,reserves);
}
}
int isreserves(int sum){
int reserves=0;
while(sum!=0){
int remain=sum%10;
reserves=reserves*10+remain;
sum=sum/10;
}
return reserves;
}

image-20240302154133137

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
//
// Created by sunny on 24.03.02.
//
#include "stdio.h"
int main(){
printf("请输入梯形的高度:");
int num=0;
scanf("%d",&num);
for (int i = 0; i < num; ++i) {
for (int j = 0; j < (num-i-1)*2; ++j) {
printf(" ");
}
for (int j = 0; j < num+i*2; ++j) {
printf("*");
}
printf("\n");
}
printf("%d",num);
}