循环-03. 求符合给定条件的整数集(15)
时间限制
400 ms
内存限制
65536 kB
代码长度限制
8000 B
判题程序
Standard
作者
徐镜春(浙江大学)
给定不超过6的正整数A,考虑从A开始的连续4个数字。请输出所有由它们组成的无重复数字的3位数。
输入格式:
输入在一行中给出A。
输出格式:
输出满足条件的的3位数,要求从小到大,每行6个整数。整数间以空格分隔,但行末不能有多余空格。
输入样例:2输出样例:
234 235 243 245 253 254 324 325 342 345 352 354 423 425 432 435 452 453 523 524 532 534 542 543
import java.util.Scanner; public class Main { public static void main(String[] args) { // TODO Auto-generated method stub Scanner in = new Scanner(System.in); int a = in.nextInt(); int[] nums = {a+1,a+2,a+3}; Main func = new Main(); int count = 1; for(int i=a*100;i<1000;i++) { int ge = i%10; int shi = i/10%10; int bai = i/100; if(judge(ge,a)&&judge(shi,a)&&judge(bai,a)&&ge!=shi&&shi!=bai&&ge!=bai) //i不含a,a+1,a+2,a+3且无重复数字 { System.out.print(i); if(count%6 != 0) { System.out.print(" "); } else if(count%6==0 && count!=0) { System.out.println(); } count++; } } } public static boolean judge(int num,int a) //判断i是否含有a,a+1,a+2,a+3 { if(num==a || num==a+1 || num==a+2 || num==a+3) { return true; } return false; } }