题解 | #百钱买百鸡问题#
百钱买百鸡问题
https://www.nowcoder.com/practice/74c493f094304ea2bda37d0dc40dc85b
#include <iostream> using namespace std; int main() { int a; cin >> a; for(int x = 0; x <= 14; x++){ if((100 - 7*x) % 4 == 0){ int y = (100-7*x)/4; int z = 100 - x - y; cout << x <<" " << y << " " << z << endl; } } }
解方程思想
5x + 3y + z/3 = 100
x + y + z = 100
可以得到,
y=(100-7x)/4,由此得到x的取值范围去遍历
z=100-x-y
华为机试刷题记录 文章被收录于专栏
记录一下手打代码的解题思路方便复习