时间:2021-07-01 10:21:17 帮助过:115人阅读
希望可以用面向对象的思想来实现
这是什么怪帐?
请说清楚点
我的理解....你说最多可分得,说明钱是可以剩余的(若不可剩余,30% 40% 30%这个分配就不对)
$member=array('a','b','c');//$member=array('a','b');//$member=array('b','c');//$member=array('b');$res = allotment(1000,$member);echo "";print_r($res);echo "";function allotment($money,$member){ $ms = array('a','b','c'); $abc = array( 'a' => 30, 'b' => 40, 'c' => 30, ); $ab = array( 'a' => 30, 'b' => 70, ); $bc = array(//B 40% C 70% 一共就 110%了,所以c 改为 60% 'b' => 40, 'c' => 60, ); $one = array( 'a' => 30, 'b' => 40, 'c' => 70, ); $same = array_intersect($ms,$member); sort($same); $res=array(); if(count($same)==1){ $data[$same[0]] = $one[$same[0]]; }else{ $plan = join('',$same); $data = $$plan; } $used = 0; foreach($data as $k=>$v){ $rate = rand(1,$v); $res[$k]['rate']=$rate.'%';//百分比 $res[$k]['mon']=$money * ($rate / 100); $used += $res[$k]['mon']; } $res['r'] = $money - $used;//剩余钱 return $res;}
3、如果B和C两个人分 B 40% C 70% 这个应该是 B 40% C 60%吧
0 && $b>0 && $c>0){ return array('a'=>$amount*0.3, 'b'=>$amount*0.4, 'c'=>$amount*0.3); } if($a>0 && $b>0 ){ return array('a'=>$amount*0.3, 'b'=>$amount*0.7, 'c'=>0); } if($b>0 && $c>0){ return array('a'=>0, 'b'=>$amount*0.4, 'c'=>$amount*0.6); } if($a>0){ return array('a'=>$amount*0.3, 'b'=>0, 'c'=>0); } if($b>0){ return array('a'=>0, 'b'=>$amount*0.4, 'c'=>0); } if($c>0){ return array('a'=>0, 'b'=>0, 'c'=>$amount*0.7); }}?>
这是什么怪帐?
请说清楚点
干掉A和B,C拿走跑路
这个意思?
function foo($u, $m=1000) { if(! is_array($u)) $u = array($u); echo join(',', $u), PHP_EOL; $d = array('A' => 0.3, 'B' => 0.4, 'C' => 0.3); foreach($u as $k) { $r[$k] = $d[$k] * $m; unset($d[$k]); } if(count($u) == 1 || count($d) == 0) return $r; foreach($d as $v) $r[$k] += $v * $m; return $r;}print_r(foo(array('A', 'B', 'C')));print_r(foo(array('A', 'B')));print_r(foo(array('A', 'C')));print_r(foo(array('B', 'C')));print_r(foo(array('B')));print_r(foo('C'));
A,B,CArray( [A] => 300 [B] => 400 [C] => 300)A,BArray( [A] => 300 [B] => 700)A,CArray( [A] => 300 [C] => 700)B,CArray( [B] => 400 [C] => 600)BArray( [B] => 400)CArray( [C] => 300)