目录
1 枚举问题_例题
1.1 abc问题
#include <cstdio>
int main() {
int a, b, c;
for (int a = 0; a <= 9; ++a) {
for (int b = 0; b <= 9; ++b) {
for (int c = 0; c <= 9; ++c) {
if(100*a+10*b+c + 100*b+11*c == 532){
printf("%d %d %d\n", a, b, c);
}
}
}
}
return 0;
}
1.2 反序数
#include <cstdio>
int Reverse(int x){
int revx = 0;
while(x != 0){
revx *= 10;
revx += x%10;
x /= 10;
}
return revx;
}
int main() {
for (int i = 1000; i <= 9999; ++i) {
if(i * 9 == Reverse(i)){
printf("%d\n", i);
}
}
return 0;
}
1.3 对称平方数1
#include <cstdio>
int Reverse(int x){
int revx = 0;
while(x != 0){
revx *= 10;
revx += x%10;
x /= 10;
}
return revx;
}
int main() {
for (int i = 0; i <= 256; ++i) {
if(i * i == Reverse(i * i)){
printf("%d\n", i);
}
}
return 0;
}
2 枚举问题_习题
2.1 与7无关的数
#include <cstdio>
int main() {
int n, sum=0;
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
if(i%7 == 0 || i/10 == 7 || i%10 == 7){
continue;
}
sum += i*i;
}
printf("%d", sum);
return 0;
}
2.2 百鸡问题
标签:10,main,int,第一章,revx,枚举,include,模拟
From: https://www.cnblogs.com/yymqdu/p/17107744.html