1.1
中国古代数学家张丘建在他的《算经》中提出了一个著名的“百钱百鸡问题”:一只公鸡值五钱,一只母鸡值三钱,三只小鸡值一钱,现在要用百钱买百鸡,请问公鸡、母鸡、小鸡各多少只?
#include <iostream> using namespace std; int main() { int cock, hen, chicken; for (cock = 0; cock <= 20; cock++) { for (hen = 0; hen <= 33; hen++) { for (chicken = 0; chicken <= 300; chicken++) { if ((cock + hen + chicken == 100) &&(5 * cock + 3 * hen + chicken / 3.0 == 100)) { cout << "公鸡数量" << cock << "母鸡数量" << hen << "小鸡数量" << chicken << endl; } } } } return 0; }
1.2
小明有5本新书,要借给A、B、C这3位小朋友,若每人每次只能借1本,则可以有多少种不同的借法?
#include <iostream> using namespace std; int main() { int a, b, c, d; d = 0; for (a = 1; a <= 5; a++) { for (b = 1; b <= 5; b++) { for (c = 1; c <= 5; c++) { if (a != b && a != c && b != c) { cout << "A:" << a << "B:" << b << "C:" << c << " "; d++; if (d % 4 == 0) { cout << endl; } } } } } return 0; }
标签:std,int,百钱,软工,namespace,include,cock From: https://www.cnblogs.com/gaoshouxiaoli/p/17316999.html