http://lx.lanqiao.cn/problem.page?gpid=T48
#include<stdio.h>
#include<algorithm>
int result[1000];
int main(){
int count = 0;
int num;
int sum;
scanf("%d", &sum);
// 1 2 3 2 1
for(int i = 0; i <= 9; i ++)
for(int x = 0; x <= 9; x++)
for(int y = 1; y <= 9; y++){
if(i + 2*x+2*y == sum){
num = i * 100 + x * 10 + x*1000 + y + y*10000;
result[count++] = num;
}
}
// 1 2 3 3 2 1
for(int i = 1; i <= 9; i ++)
for(int x = 0; x <= 9; x++)
for(int y = 0; y <= 9; y++){
if(i*2 + 2*x+2*y == sum){
num = i * 100000 + i + x * 10 + x*10000 + y*100 + y*1000;
result[count++] = num;
}
}
std::sort(result, result+count);
for(int i = 0; i < count; i++)
if(i != count - 1)
printf("%d\n", result[i]);
else
printf("%d", result[i]);
return 0;
}
网友评论