题解 | #百钱买百鸡问题#
百钱买百鸡问题
https://www.nowcoder.com/practice/74c493f094304ea2bda37d0dc40dc85b
#include <stdio.h> #define MAX 101 int main() { int a[MAX], b[MAX], c[MAX]; int n; while (scanf("%d", &n)!= EOF) { // 计算公鸡数量数组 for (int i = 0; i < MAX; i += 5) { a[i] = i / 5; // printf("公鸡a[%d] = %d\n", i, a[i]); } // 计算母鸡数量数组 for (int i = 0; i < MAX; i += 3) { b[i] = i / 3; // printf("母鸡a[%d] = %d\n", i, b[i]); } // 计算雏鸡数量数组 for (int i = 0; i < MAX; i++) { c[i] = 3 * i; } for (int i = 0; i < MAX; i += 5) { for (int j = 0; j < MAX; j += 3) { for (int k = 0; k < MAX; k++) { if ((a[i] * 5 + b[j] * 3 + c[k] / 3 == 100) && (a[i] + b[j] + c[k] == 100)) { printf("%d %d %d\n", a[i], b[j], c[k]); } } } } } return 0; }