zoukankan      html  css  js  c++  java
  • Java实现 洛谷 P1618 三连击(升级版)

    在这里插入图片描述

    import java.util.Arrays;
    import java.util.Scanner;
     
    public class Main {
    	private static Scanner cin;
    	private static boolean hasFound = false; 
    	
    	public static void main(String args[]) throws Exception {
    		cin = new Scanner(System.in);
    		int A = cin.nextInt();
    		int B = cin.nextInt();
    		int C = cin.nextInt();
    		
    		for(int i = 123;i<=987;i++) {
    			if(i%A==0) {
    				if(String.valueOf(i).contains("0")) {
    					continue;
    				}
    				int j = i/A*B;
    				if(j<123 || j>987 || String.valueOf(j).contains("0")) {
    					continue;
    				}else {
    					int k = i/A*C;
    					if(k<123 || k>987 || String.valueOf(k).contains("0")) {
    						continue;
    					}else {
    						checkDigit(i,j,k);
    					}
    				}
    			}
    		}
    		if(!hasFound) {
    			System.out.println("No!!!");
    		}
    				
    	}
    	
    	//check if i,j,k has different digits from 1 to 9
    	public static void checkDigit(int i,int j,int k) {
    		int[] digits = new int[9];
    		Arrays.fill(digits, 0);
    		int a = i/100;
    		int b = (i-a*100)/10;
    		int c = (i-a*100 - b*10);
    		if(a == b || b== c || a==c) {
    			return;
    		}
    		if(digits[a-1] ==1 || digits[b-1] == 1 || digits[c-1] == 1) {
    			return;
    		}else {
    			digits[a-1] = 1;
    			digits[b-1] = 1;
    			digits[c-1] = 1;
    			a = j/100;
    			b = (j-a*100)/10;
    			c = (j-a*100 - b*10);
    			if(a == b || b== c || a==c) {
    				return;
    			}
    			if(digits[a-1] ==1 || digits[b-1] == 1 || digits[c-1] == 1) {
    				return;
    			}else {
    				digits[a-1] = 1;
    				digits[b-1] = 1;
    				digits[c-1] = 1;
    				a = k/100;
    				b = (k-a*100)/10;
    				c = (k-a*100 - b*10);
    				if(a == b || b== c || a==c) {
    					return;
    				}
    				if(digits[a-1] ==1 || digits[b-1] == 1 || digits[c-1] == 1) {
    					return;
    				}else {
    					System.out.println(String.format("%d %d %d", i,j,k));
    					if(!hasFound) {
    						hasFound = true;
    					}
    				}
    			}
    		}
    	}
    }
    
  • 相关阅读:
    一个强大的json解析工具类
    android存储路径问题
    android界面的滑动切换功能
    mysql数据库
    【hadoop+spark】搭建spark过程
    【设计模式】行为型01策略模式(strategy patten)
    【java爬虫】网络爬虫思路
    maven_nexus私服搭建
    【需要重新维护】Redis笔记20170811视频
    【工具】java 文本文档txt写出记录工具
  • 原文地址:https://www.cnblogs.com/a1439775520/p/12947122.html
Copyright © 2011-2022 走看看