原题链接
这题比较坑人,如果题目没有给定输入范围,则在输入后需要判断输入是否合法。
#include <stdio.h>
#include <stdlib.h>
char str[7];
bool Judge(int a){
int i = 0;
while(a){
str[i++] = a % 10 + '0';
if(str[i-1] > '6') return 0;
a /= 10;
}
while(i < 6) str[i++] = '0';
str[i] = '\0';
for(i = 1; i != 6; ++i){
if(str[i] == str[i+1] && str[i] == str[i-1]) return 0;
if(abs(str[i] - str[i-1]) > 4) return 0;
}
return 1;
}
int main(){
int t, a, b, i;
scanf("%d", &t);
while(t--){
scanf("%d%d", &a, &b);
for(i = a; i <= b; ++i)
if(Judge(i)) printf("%06d\n", i);
printf("\n");
}
return 0;
}