百钱百鸡

    科技2022-07-11  105

    Java 的百钱百鸡

    比较简单,直接循环就完事了

    package 数据结构练习1; public class 百元百鸡 { public static void main(String[] args) { int cock; //鸡的数量 int hen,chi; for( cock = 0;cock<=20;cock++) { for( hen = 0;hen<=33;hen++) { for( chi = 0;chi<=300;chi++) { if(hen+cock+chi == 100 && hen*3+cock*5+chi*1/3 == 100) { System.out.println("cock:"+cock+",hen"+hen+",chicken:"+chi); } } } } //千💴千🐥 for( cock = 0;cock<=200;cock++) { for( hen = 0;hen<=333;hen++) { for( chi = 0;chi<=3000;chi++) { if(hen+cock+chi == 1000 && hen*3+cock*5+chi*1/3 == 1000) { //System.out.println("cock:"+cock+",hen"+hen+",chicken:"+chi); } } } } //万💴万🐥 for( cock = 0;cock<=2000;cock++) { for( hen = 0;hen<=3333;hen++) { for( chi = 0;chi<=30000;chi++) { if(hen+cock+chi == 10000 && hen*3+cock*5+chi*1/3 == 10000) { //System.out.println("cock:"+cock+",hen"+hen+",chicken:"+chi); } } } } } }
    Processed: 0.275, SQL: 8