" 鸡有 100 只 花了100元
" 小鸡 1 元 3 只
" 公鸡 3 元 1 只
" 母鸡 5 元 1只
DATA:money TYPE p.
DATA:BEGIN OF gt_sturt OCCURS 0,
chick TYPE i,"小鸡
hen TYPE i,"母鸡
cock TYPE i,"公鸡
END OF gt_sturt.
"因为100元 100只 所以 平均每只鸡 1元 所以 可以得到 (5*x+3*y+1/3*z) / (x+y+z) = 1
" => 12x + 6y - 2z = 0 => 6X + 3Y = Z
gt_sturt-hen = - 1.
gt_sturt-cock = - 1.
gt_sturt-chick = - 1.
WHILE 5 * gt_sturt-hen < 100.
gt_sturt-hen = gt_sturt-hen + 1.
WHILE 5 * gt_sturt-hen + 3 * gt_sturt-cock < 100.
gt_sturt-cock = gt_sturt-cock + 1.
money = 7 * gt_sturt-hen + 4 * gt_sturt-cock.
CHECK money EQ 100.
gt_sturt-chick = 6 * gt_sturt-hen + 3 * gt_sturt-cock. "Z / 3 = 2 * X + Y
APPEND gt_sturt.
WRITE:/ '母鸡有:',gt_sturt-hen,'只','公鸡有:',gt_sturt-cock,'只','小鸡有:',gt_sturt-chick,'只'.
CLEAR money.
ENDWHILE.
CLEAR gt_sturt-cock.
ENDWHILE.
结果: