这些代码怎么写?搞定后即给分!

YewPu 2003-09-12 02:58:03
有没有这个一个程序:
计算出发放工资所需要的人民币面额:
例如:589.5元
需5张100元,1张50元,1张20元1张10元,1张5元,2张2元和1张5角。


谢谢!
...全文
28 30 打赏 收藏 转发到动态 举报
写回复
用AI写文章
30 条回复
切换为时间正序
请发表友善的回复…
发表回复
qqjj7758 2003-10-23
  • 打赏
  • 举报
回复
不是很难啊 数字都是固定的
baiyga 2003-10-23
  • 打赏
  • 举报
回复
求余取整即可啊!

YewPu 2003-10-23
  • 打赏
  • 举报
回复
UP
eminena 2003-09-23
  • 打赏
  • 举报
回复
http://expert.csdn.net/Expert/topic/2026/2026753.xml?temp=.7696192
eminena 2003-09-23
  • 打赏
  • 举报
回复
double ld_money = 1123456789.34 // 输入的钱,变量
int li_small // 钱的小数部分
long ll_big // 钱的整数部分
int li_loop // 循环用临时变量

long ll_moneyrest // 计算用钱的余值

string ls_result1 // 存放整数计算结果
string ls_result2 // 存放小数计算结果

parent.title = string(ld_money)

// 以元为单位,将币种放入数组
int li_big_part[]={100,50,20,10,5,2,1}
// 存放相对应于币种数组的张数
long ll_big_count[7]

// 以分为单位,将币种放入数组
int li_small_part[]={50,20,10,5,2,1}
// 存放相对应于币种数组的张数
int li_small_count[6]

// 得到钱的整数部分
ll_big=long(ld_money)

// 得到钱的小数部分
li_small=int((round(ld_money,2)-ll_big) * 100)

ll_moneyrest = ll_big // 初始化余值

// 执行循环,找出整数部分的对应币种的张数

for li_loop = 1 to 7
if ll_big <=0 then exit
ll_big_count[li_loop] = long( ll_moneyrest / li_big_part[li_loop] )
ll_moneyrest = mod(ll_moneyrest, li_big_part[li_loop])
next

ll_moneyrest = li_small // 初始化余值

// 执行循环,找出小数部分的对应币种的张数

for li_loop = 1 to 6
if li_small <=0 then exit
li_small_count[li_loop] = int( ll_moneyrest / li_small_part[li_loop] )
ll_moneyrest = mod(ll_moneyrest, li_small_part[li_loop])
next

// 将整数部分的所有结果存放于 ls_result1
for li_loop = 1 to 7 step 1
if ll_big_count[li_loop] = 0 then continue
ls_result1 = ls_result1 + string(li_big_part[li_loop]) + &
"元=" + string(ll_big_count[li_loop]) + "张 "

next

// 将小数部分的所有结果存放于 ls_result2
for li_loop = 1 to 6 step 1
if li_small_count[li_loop] = 0 then continue
if li_loop < 4 then
ls_result2 = ls_result2 + string(li_small_part[li_loop]/10) + &
"角=" + string(li_small_count[li_loop]) + "张 "
else
ls_result2 = ls_result2 + string(li_small_part[li_loop]) + &
"分=" + string(li_small_count[li_loop]) + "张 "
end if
next

// 显示结果
messagebox("计算结果为:", ls_result1+"~r~n~r~n"+ls_result2)
YewPu 2003-09-23
  • 打赏
  • 举报
回复
谢谢!
codecopyking 2003-09-23
  • 打赏
  • 举报
回复
面值是相当固定的,这让就比较容易了,
从大面值向小面值推就行了!
Jonea 2003-09-17
  • 打赏
  • 举报
回复
double ldc_cash[] = {100,50,20,10,5,2,1,0.5,0.1} //钱的面值
int li_return[] //钱币数量
int li_rd //
double ldc_value = 589.5 //金额

for li_rd = 1 to UpperBound(ldc_cash)
if ldc_value >= ldc_cash[li_rd] then
li_return[li_rd] = ldc_value / ldc_cash[li_rd]
ldc_value = ldc_value - (li_return[li_rd] *ldc_cash[li_rd])
else
li_return[li_rd] = 0
end if
end for

//li_return 数组里边就是存放着钱币张数.和面值数相对应。

呵呵。手上没有pb进行调试.不知道有没有错。
YewPu 2003-09-16
  • 打赏
  • 举报
回复
csdsjkk() 果然好建议啊!

xiahouyi 2003-09-14
  • 打赏
  • 举报
回复
具体怎么编啊?写一下
csdsjkk 2003-09-14
  • 打赏
  • 举报
回复
分成58950个1分
yk80 2003-09-14
  • 打赏
  • 举报
回复
朋友,你的想法不对(个人认为)我可把589.5分成10张50元的和8张10元和9张1元和5个1分
liliang800207 2003-09-14
  • 打赏
  • 举报
回复
反复的求余取倍数是最简单的方法
jdsnhan 2003-09-14
  • 打赏
  • 举报
回复
好象数据结构中有个算法叫贪婪法,求这样的结果。
此时,肯定不是一种答案,但需最优。
YewPu 2003-09-14
  • 打赏
  • 举报
回复
to: andyzq(小强) 你的贴子主题是什么啊?
rogery 2003-09-13
  • 打赏
  • 举报
回复
同意: andyzq(小强)

csdn上有这样的帖子。找一下吧。
yingmu 2003-09-12
  • 打赏
  • 举报
回复
王行舟的理论加csdsjkk的例子,高手!
klbt 2003-09-12
  • 打赏
  • 举报
回复
自己写一个通用函数吧。用模可以实现。
eaglechou 2003-09-12
  • 打赏
  • 举报
回复
自己写个酸法把
一般这类问题都是有规律可寻的
用个循环求模的酸法应该可以
csdsjkk 2003-09-12
  • 打赏
  • 举报
回复
double xx[]={100,50,20,10,5,2,1, .5, .2,.1}
long yy[]

long l
double s=589.5,s1

for l =1 to upperbound(xx)
s1=int(s / xx[l])
if s1 > 0 then
yy[l]=s1
s = s - s1 * xx[l]
end if
next
加载更多回复(10)

1,072

社区成员

发帖
与我相关
我的任务
社区描述
PowerBuilder 相关问题讨论
社区管理员
  • 基础类社区
  • WorldMobile
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧