"Huawei OJ" "Algorithm Total chapter" "Huawei OJ" "047-hundred money buy Hundred chicken Problem" "Project Download" topic description
公元前五世纪,我国古代数学家张丘建在《算经》一书中提出了“百鸡问题”:鸡翁一值钱五,鸡母一值钱三,鸡雏三值钱一。百钱买百鸡,问鸡翁、鸡母、鸡雏各几何? 详细描述: 接口说明 原型: int getResult()
Enter a description
无
Output description
list 鸡翁、鸡母、鸡雏组合的列表
Input example
1
Output example
0 25 754 18 788 11 8112 4 84
Algorithm implementation
ImportJava.util.Scanner;/** * Author: Wang Junshu * date:2015-12-25 08:15 * declaration:all rights Reserved!!! */ Public class Main { Public Static void Main(string[] args) {//scanner Scanner = new Scanner (system.in);Scanner Scanner =NewScanner (Main.class.getClassLoader (). getResourceAsStream ("Data.txt")); while(Scanner.hasnext ()) {Scanner.nextline (); System.out.print (GetResult ()); } scanner.close (); }/** * Chicken Weng (x), chicken Mother (y), chickens (z) problem is to ask for 5x + 3y+ Z/3 and all possible solutions for x + y + z * * @return */ Public StaticStringGetResult() {StringBuilder builder =NewStringBuilder (); for(intx =0; X <= -; X + +) { for(inty =0; Y <= --X; y++) {intz = --X-y;if(Z%3==0&& -==5* x +3* y + z/3) {builder.append (x). Append ("'). Append (y). Append ("'). Append (z). Append (' \ n '); } } }returnBuilder.tostring (); }}
"Huawei OJ" "047-hundred money buy hundred chicken problem"