- 论坛徽章:
- 0
|
本帖最后由 xyl5565 于 2015-09-14 18:16 编辑
终于搞定 bug害人
//不知道n
//条件
import console
数组1={}
数组2={}
n=console.getNumber( "请输入每个数组元素个数: " )
for(i=1;n;1)
{
table.push(数组1,console.getNumber( "请输入数组1的第"+i+"个元素:" ))
}
for(i=1;n;1)
{
table.push(数组2,console.getNumber( "请输入数组2的第"+i+"个元素:" ))
}
//功能函数
getsum=function(ts)
{
if(not #ts)
{
return 0;
}
sum=0
for(k,v in ts)
{
sum+=v
}
return sum;
}
s3=table.concat(数组1,数组2)
table.sort(s3)
数组1={}
数组2={}
while(#s3>0)//有数字就继续取
{
sum2=getsum(数组2)
sum1=getsum(数组1)
t1=数组1
t2=数组2
if(sum2>sum1)
{
t1=数组2
t2=数组1
}
n=table.pop(s3,1)
table.push(t2,n)
sum2=getsum(t2)
sum1=getsum(t1)
for(i=1;#s3;1)
{
if((sum1+s3)>=sum2)
{
l=i
break ;
}
l=i
}
table.push(t1,s3[l])
table.remove(s3,l)
}
console.log('数组:')
console.log(table.tostring(数组1))
console.log(table.tostring(数组2))
console.log('和为:')
console.log(getsum(数组1))
console.log(',')
console.log(getsum(数组2))
execute("pause") |
|