题解 | #百鸡问题#
百鸡问题
https://www.nowcoder.com/practice/01d161052db64c249a47fc723b4fd5db
#include <bits/stdc++.h> using namespace std; int main() { int n = 0; cin >> n; float sum = 0; for (int x = 0; x <= 100; ++x) { for (int y = 0; y <= 100 - x; ++y) { for (int z = 0; z <= 100 - y - x; ++z) { sum = x * 5 + y * 3 + z * 1.0 / 3; if (x + y + z == 100 && sum <= n) { printf("x=%d,y=%d,z=%d\n", x, y, z); //无&符号 } } } } return 0; }