D
Delphi刘
Unregistered / Unconfirmed
GUEST, unregistred user!
各位大虾:
算法求解
有这样一些数据
序号 时间 优惠价额 汇入金额 期限(天) 利息
1 2003-1-1 8000 5000 30
2 2003-1-5 3000 2000 30
3 2003-2-6 1000 2000 30
4 2003-3-9 3000 4000 30
5 2003-4-6 2000
要求将利息算出来并保存到相应的记录
如:第一笔记录的利息是:
payoff:=第一笔优惠价额减去第一笔汇入价额 (8000-5000)
G_qixian:=第二笔汇入金额的时间减去第一笔的时间-30 (2003-1-5减去2003-1-1)
如果过期了(G_qixian>0),
Interest:=payoff*G_qixian*0.01/30;
如果没过期
Interest:=0;
如果没还清(payoff>0),继续找下一笔汇入金额
payoff:=payoff-第二笔汇入金额;(3000-2000)
G_qixian:=第三笔汇入金额的时间-第二笔汇入金额的时间
Interest:=Interest+payoff*G_qixian *利率 (0.01/30)
...
如果第一笔一直没还清
G_qixian:=今天减去最后一笔汇入金额的时间
Interest:=Interest+payoff*G_qixian;
如果还清了还有多就放到还下一笔帐上
...
一直到还清第一笔再来算第二笔的利息
多少笔记录是不固定的
本人数据结构没学好,总结不出一个好的算法,用死方法在算,可记录
一超过2条就把个脑袋给转晕了。所以非常希望各位大虾帮帮忙救急。
附:
case Rec of
//---------------------------------------------------------
//if only have one record
//---------------------------------------------------------
1:
begin
Interest:=0;
payoff:=Cal_Interest[0].yh_Price-Cal_Interest[0].hr_Money;
G_qixian:=Trunc(Date-Cal_Interest[0].DateTime)-30;
if G_qixian>0 then
begin
Interest:=Interest+payoff*G_qixian*0.01/30;
end
else
Interest:=Interest+0;
Edit;
FieldByName('Interest').AsCurrency:=Interest;
Post;
end;
//-----------------------------------------------
//if there are two records
//-----------------------------------------------
2:
begin
First;
Interest:=0;
payoff:=Cal_Interest[0].yh_Price-Cal_Interest[0].hr_Money;
if Cal_Interest[1].hr_Money>0 then
//if have remittance
begin
G_qixian:=Trunc(Cal_Interest[1].DateTime-Cal_Interest[0].DateTime)-30;
if G_qixian>0 then
//if the second remittance excess 30 days
begin
Interest:=Interest+payoff*G_qixian*0.01/30;
payoff:=payoff-Cal_Interest[1].hr_Money;
if payoff>0 then
//if not pay off
begin
G_qixian:=Trunc(Date-Cal_Interest[1].DateTime);
Interest:=Interest+payoff*G_qixian*0.01/30;
payoff1:=-1;
end;
if payoff=0 then
begin
G_qixian:=Trunc(Cal_Interest[1].DateTime-Cal_Interest[0].DateTime);
Interest:=Interest+payoff*G_qixian*0.01/30;
payoff1:=-1;
end;
if payoff<0 then
begin
payoff1:=payoff;
end;
end
else
//if the second remittance havn't excess 30 days
begin
payoff:=payoff-Cal_Interest[1].hr_Money;
if payoff>0 then
//if not pay off
begin
G_qixian:=Trunc(Date-Cal_Interest[0].DateTime)-30;
if G_qixian>0 then
Interest:=Interest+payoff*G_qixian*0.01/30
else
Interest:=0;
payoff1:=0;
end;
if payoff=0 then
begin
G_qixian:=Trunc(Date-Cal_Interest[0].DateTime)-30;
if G_qixian>0 then
Interest:=Interest+payoff*G_qixian*0.01/30
else
Interest:=0;
payoff1:=0;
end;
if payoff<0 then
begin
payoff1:=payoff;
end;
end;
//end else
G_qixian<30
end
else
//if have no hr_Money
begin
G_qixian:=Trunc(Date-Cal_Interest[0].DateTime)-30;
if G_qixian>0 then
Interest:=payoff*G_qixian*0.01/30
else
Interest:=0;
end;
Edit;
FieldByName('Interest').AsCurrency:=Interest;
Post;
Next;
begin
if (Cal_Interest[1].yh_Price>0) then
begin
G_qixian:=Trunc(Date-Cal_Interest[1].DateTime)-30;
if G_qixian>0 then
begin
if (payoff1<0) then
payoff:=Cal_Interest[1].yh_Price+payoff1
else
payoff:=Cal_Interest[1].yh_Price;
Interest:=payoff*G_qixian*0.01/30;
end
else
Interest:=0;
end
else
Interest:=0;
end;
Edit;
FieldByName('Interest').AsCurrency:=Interest;
Post;
end;
//end case 2
算法求解
有这样一些数据
序号 时间 优惠价额 汇入金额 期限(天) 利息
1 2003-1-1 8000 5000 30
2 2003-1-5 3000 2000 30
3 2003-2-6 1000 2000 30
4 2003-3-9 3000 4000 30
5 2003-4-6 2000
要求将利息算出来并保存到相应的记录
如:第一笔记录的利息是:
payoff:=第一笔优惠价额减去第一笔汇入价额 (8000-5000)
G_qixian:=第二笔汇入金额的时间减去第一笔的时间-30 (2003-1-5减去2003-1-1)
如果过期了(G_qixian>0),
Interest:=payoff*G_qixian*0.01/30;
如果没过期
Interest:=0;
如果没还清(payoff>0),继续找下一笔汇入金额
payoff:=payoff-第二笔汇入金额;(3000-2000)
G_qixian:=第三笔汇入金额的时间-第二笔汇入金额的时间
Interest:=Interest+payoff*G_qixian *利率 (0.01/30)
...
如果第一笔一直没还清
G_qixian:=今天减去最后一笔汇入金额的时间
Interest:=Interest+payoff*G_qixian;
如果还清了还有多就放到还下一笔帐上
...
一直到还清第一笔再来算第二笔的利息
多少笔记录是不固定的
本人数据结构没学好,总结不出一个好的算法,用死方法在算,可记录
一超过2条就把个脑袋给转晕了。所以非常希望各位大虾帮帮忙救急。
附:
case Rec of
//---------------------------------------------------------
//if only have one record
//---------------------------------------------------------
1:
begin
Interest:=0;
payoff:=Cal_Interest[0].yh_Price-Cal_Interest[0].hr_Money;
G_qixian:=Trunc(Date-Cal_Interest[0].DateTime)-30;
if G_qixian>0 then
begin
Interest:=Interest+payoff*G_qixian*0.01/30;
end
else
Interest:=Interest+0;
Edit;
FieldByName('Interest').AsCurrency:=Interest;
Post;
end;
//-----------------------------------------------
//if there are two records
//-----------------------------------------------
2:
begin
First;
Interest:=0;
payoff:=Cal_Interest[0].yh_Price-Cal_Interest[0].hr_Money;
if Cal_Interest[1].hr_Money>0 then
//if have remittance
begin
G_qixian:=Trunc(Cal_Interest[1].DateTime-Cal_Interest[0].DateTime)-30;
if G_qixian>0 then
//if the second remittance excess 30 days
begin
Interest:=Interest+payoff*G_qixian*0.01/30;
payoff:=payoff-Cal_Interest[1].hr_Money;
if payoff>0 then
//if not pay off
begin
G_qixian:=Trunc(Date-Cal_Interest[1].DateTime);
Interest:=Interest+payoff*G_qixian*0.01/30;
payoff1:=-1;
end;
if payoff=0 then
begin
G_qixian:=Trunc(Cal_Interest[1].DateTime-Cal_Interest[0].DateTime);
Interest:=Interest+payoff*G_qixian*0.01/30;
payoff1:=-1;
end;
if payoff<0 then
begin
payoff1:=payoff;
end;
end
else
//if the second remittance havn't excess 30 days
begin
payoff:=payoff-Cal_Interest[1].hr_Money;
if payoff>0 then
//if not pay off
begin
G_qixian:=Trunc(Date-Cal_Interest[0].DateTime)-30;
if G_qixian>0 then
Interest:=Interest+payoff*G_qixian*0.01/30
else
Interest:=0;
payoff1:=0;
end;
if payoff=0 then
begin
G_qixian:=Trunc(Date-Cal_Interest[0].DateTime)-30;
if G_qixian>0 then
Interest:=Interest+payoff*G_qixian*0.01/30
else
Interest:=0;
payoff1:=0;
end;
if payoff<0 then
begin
payoff1:=payoff;
end;
end;
//end else
G_qixian<30
end
else
//if have no hr_Money
begin
G_qixian:=Trunc(Date-Cal_Interest[0].DateTime)-30;
if G_qixian>0 then
Interest:=payoff*G_qixian*0.01/30
else
Interest:=0;
end;
Edit;
FieldByName('Interest').AsCurrency:=Interest;
Post;
Next;
begin
if (Cal_Interest[1].yh_Price>0) then
begin
G_qixian:=Trunc(Date-Cal_Interest[1].DateTime)-30;
if G_qixian>0 then
begin
if (payoff1<0) then
payoff:=Cal_Interest[1].yh_Price+payoff1
else
payoff:=Cal_Interest[1].yh_Price;
Interest:=payoff*G_qixian*0.01/30;
end
else
Interest:=0;
end
else
Interest:=0;
end;
Edit;
FieldByName('Interest').AsCurrency:=Interest;
Post;
end;
//end case 2