看到.net的人搞算法,我出200分,大家也玩一下

AFIC 2007-03-01 03:41:00
题如下:求数值在 1 - 50 之内的任意5个数之和为100 。

数值:1,2,3,4,5,6....48,49,50
取其中的任意5个数,但这5个数相加之和要等于100,并将所有这种组合罗列
例: 1+10+19+20+50=100
3+14+16+27+40=100

这题太简单了,随改为,
求数值在 1 - n 之内的任意x个数之和为y 。
也就是说,要求3个数都可以自定义。

1看清楚是自定义,我改了题
2俺来当裁判,只比运行效率,说白了两个cpu想减。
3每人可多次参加,只算最高的
4输出尽量到dw或ds(1列放1+10+19+20+50这种),不是的俺会尽量更改
5结果错算法无效,只给参加的人分(平分,无视效率,重在参与)
6最晚截至到4月1日
...全文
941 55 打赏 收藏 转发到动态 举报
写回复
用AI写文章
55 条回复
切换为时间正序
请发表友善的回复…
发表回复
AFIC 2007-03-27
  • 打赏
  • 举报
回复
揭帖了,兄弟们接口不太一样,感觉测试不太公平。
AFIC 2007-03-12
  • 打赏
  • 举报
回复
兄弟们不好意思阿,最近忽然有点忙,
等忙过了一定给大家好好测试一下。
chinalht 2007-03-12
  • 打赏
  • 举报
回复
type cb_1 from commandbutton within w_sf
int X=1957
int Y=464
int Width=288
int Height=96
int TabOrder=50
string Text="计算"
int TextSize=-9
int Weight=400
string FaceName="宋体"
FontCharSet FontCharSet=GB2312CharSet!
FontPitch FontPitch=Variable!
end type

event clicked;long n, lx, ly, ln[]
long i, sum, t1, t2, t3
string ls_null[]

n = long(sle_1.text)
lx = long(sle_2.text)
ly = long(sle_3.text)
sum = n * (n + 1) / 2
if n < 1 or ly < 1 or lx > n or (sum < ly) or (sum = ly and lx <> 1) then
messagebox('','输入数据不符合要求!')
return
end if
setpointer(hourglass!)
dw_1.reset()
is_result = ls_null
il_count = 0
ln[lx] = 0
t1 = cpu()
for i = 1 to n
is_num[i] = string(i)
next
wf_calc(n, lx, ly, ln)
t2 = cpu()
if il_count > 0 then
dw_1.object.result.original = is_result
end if
t3 = cpu()
setpointer(arrow!)
messagebox('', '共' + string(il_count) + '个结果,耗时' + string(t3 - t1) + '毫秒(' + string(t2 - t1) + '+' + string(t3 - t2) + ')')

end event

type st_3 from statictext within w_sf
int X=1902
int Y=288
int Width=247
int Height=76
boolean Enabled=false
string Text="之和为"
boolean FocusRectangle=false
long TextColor=33554432
long BackColor=67108864
int TextSize=-9
int Weight=400
string FaceName="宋体"
FontCharSet FontCharSet=GB2312CharSet!
FontPitch FontPitch=Variable!
end type

type st_1 from statictext within w_sf
int X=1915
int Y=72
int Width=247
int Height=76
boolean Enabled=false
string Text="从 1 到"
boolean FocusRectangle=false
long TextColor=33554432
long BackColor=67108864
int TextSize=-9
int Weight=400
string FaceName="宋体"
FontCharSet FontCharSet=GB2312CharSet!
FontPitch FontPitch=Variable!
end type

type sle_3 from singlelineedit within w_sf
int X=2171
int Y=272
int Width=384
int Height=92
int TabOrder=40
BorderStyle BorderStyle=StyleLowered!
boolean AutoHScroll=false
string Text="100"
long TextColor=33554432
int TextSize=-9
int Weight=400
string FaceName="宋体"
FontCharSet FontCharSet=GB2312CharSet!
FontPitch FontPitch=Variable!
end type

type sle_2 from singlelineedit within w_sf
int X=2171
int Y=164
int Width=384
int Height=92
int TabOrder=30
BorderStyle BorderStyle=StyleLowered!
boolean AutoHScroll=false
string Text="5"
long TextColor=33554432
int TextSize=-9
int Weight=400
string FaceName="宋体"
FontCharSet FontCharSet=GB2312CharSet!
FontPitch FontPitch=Variable!
end type

type sle_1 from singlelineedit within w_sf
int X=2171
int Y=56
int Width=384
int Height=92
int TabOrder=20
BorderStyle BorderStyle=StyleLowered!
boolean AutoHScroll=false
string Text="50"
long TextColor=33554432
int TextSize=-9
int Weight=400
string FaceName="宋体"
FontCharSet FontCharSet=GB2312CharSet!
FontPitch FontPitch=Variable!
end type

type dw_1 from datawindow within w_sf
int X=18
int Y=12
int Width=1801
int Height=1392
int TabOrder=10
BorderStyle BorderStyle=StyleLowered!
boolean HScrollBar=true
boolean VScrollBar=true
boolean LiveScroll=true
end type

type st_2 from statictext within w_sf
int X=1911
int Y=180
int Width=782
int Height=76
boolean Enabled=false
string Text="选取 个数"
boolean FocusRectangle=false
long TextColor=33554432
long BackColor=67108864
int TextSize=-9
int Weight=400
string FaceName="宋体"
FontCharSet FontCharSet=GB2312CharSet!
FontPitch FontPitch=Variable!
end type

chinalht 2007-03-12
  • 打赏
  • 举报
回复
优化以后的
$PBExportHeader$w_sf.srw
forward
global type w_sf from Window
end type
type cb_2 from commandbutton within w_sf
end type
type cb_1 from commandbutton within w_sf
end type
type st_3 from statictext within w_sf
end type
type st_1 from statictext within w_sf
end type
type sle_3 from singlelineedit within w_sf
end type
type sle_2 from singlelineedit within w_sf
end type
type sle_1 from singlelineedit within w_sf
end type
type dw_1 from datawindow within w_sf
end type
type st_2 from statictext within w_sf
end type
end forward

global type w_sf from Window
int X=1326
int Y=512
int Width=2793
int Height=1572
boolean TitleBar=true
string Title="PB"
long BackColor=80269524
boolean ControlMenu=true
boolean MinBox=true
boolean MaxBox=true
boolean Resizable=true
cb_2 cb_2
cb_1 cb_1
st_3 st_3
st_1 st_1
sle_3 sle_3
sle_2 sle_2
sle_1 sle_1
dw_1 dw_1
st_2 st_2
end type
global w_sf w_sf

type variables
string is_result[]
long il_count
string is_num[]

integer ii_number[]
string is_exp[]

end variables

forward prototypes
public function long wf_calc (long n, long lx, long ly, ref long ln[])
end prototypes

public function long wf_calc (long n, long lx, long ly, ref long ln[]);//====================================================================
// 函数名称: wf_calc
//--------------------------------------------------------------------
// 功能描述:
//--------------------------------------------------------------------
// 传递参数:
// long n 共有从1到n个整数
// long lx 选择lx个数
// long ly 其和等于ly
// long ln[] 返回选择出的数
// 返回参数: long
//--------------------------------------------------------------------
// 代码设计: liuht 日期: 2007-03-06
//--------------------------------------------------------------------
// 修改历史:
//====================================================================
long i

if lx = 1 then
if ly <= n then
il_count ++
is_result[il_count] = is_num[ly]
for i = 2 to upperbound(ln)
is_result[il_count] += "+" + is_num[ln[i]]
next
return 1
end if
return 0
end if
if n >= ly then n = ly - (lx - 1) * lx / 2
for i = n to lx step -1
if (i * ( i + 1)) < (ly + ly) then exit
ln[lx] = i
wf_calc(i - 1, lx - 1, ly - i, ln)
next
return 0
end function

on w_sf.create
this.cb_2=create cb_2
this.cb_1=create cb_1
this.st_3=create st_3
this.st_1=create st_1
this.sle_3=create sle_3
this.sle_2=create sle_2
this.sle_1=create sle_1
this.dw_1=create dw_1
this.st_2=create st_2
this.Control[]={this.cb_2,&
this.cb_1,&
this.st_3,&
this.st_1,&
this.sle_3,&
this.sle_2,&
this.sle_1,&
this.dw_1,&
this.st_2}
end on

on w_sf.destroy
destroy(this.cb_2)
destroy(this.cb_1)
destroy(this.st_3)
destroy(this.st_1)
destroy(this.sle_3)
destroy(this.sle_2)
destroy(this.sle_1)
destroy(this.dw_1)
destroy(this.st_2)
end on

event open;string ls_syntax

ls_syntax = 'release 6;~r~n' + &
'datawindow(units=0 timer_interval=0 color=16777215 processing=1 print.documentname="" print.orientation = 0 print.margin.left = 110 print.margin.right = 110 print.margin.top = 96 print.margin.bottom = 96 print.paper.source = 0 print.paper.size = 0 print.prompt=no print.buttons=no print.preview.buttons=no grid.lines=0 ) ~r~n' + &
'header(height=68 color="536870912" ) ~r~n' + &
'summary(height=0 color="536870912" ) ~r~n' + &
'footer(height=0 color="536870912" ) ~r~n' + &
'detail(height=80 color="536870912" ) ~r~n' + &
'table(column=(type=char(150) updatewhereclause=yes name=result dbname="result" ) ~r~n' + &
' ) ~r~n' + &
'text(band=header alignment="2" text="序号"border="6" color="0" x="9" y="8" height="56" width="215" font.face="宋体" font.height="-9" font.weight="400" font.family="0" font.pitch="2" font.charset="134" background.mode="2" background.color="80269524" ) ~r~n' + &
'text(band=header alignment="2" text="Result"border="6" color="0" x="233" y="8" height="56" width="1353" name=result_t font.face="宋体" font.height="-9" font.weight="400" font.family="0" font.pitch="2" font.charset="134" background.mode="2" background.color="80269524" ) ~r~n' + &
'column(band=detail id=1 alignment="0" tabsequence=10 border="0" color="0" x="233" y="4" height="72" width="1353" format="[general]" name=result edit.limit=0 edit.case=any edit.focusrectangle=no edit.autoselect=yes edit.autohscroll=yes font.face="宋体" font.height="-9" font.weight="400" font.family="2" font.pitch="2" font.charset="134" background.mode="1" background.color="536870912" ) ~r~n' + &
'compute(band=detail alignment="0" expression="getrow()"border="0" color="0" x="9" y="4" height="72" width="215" format="[general]" font.face="宋体" font.height="-9" font.weight="400" font.family="0" font.pitch="2" font.charset="134" background.mode="2" background.color="16777215" ) ~r~n' + &
'htmltable(border="1" cellpadding="0" cellspacing="0" generatecss="no" nowrap="yes") '
dw_1.create(ls_syntax)
end event

type cb_2 from commandbutton within w_sf
int X=2322
int Y=464
int Width=288
int Height=96
int TabOrder=60
string Text="退出"
int TextSize=-9
int Weight=400
string FaceName="宋体"
FontCharSet FontCharSet=GB2312CharSet!
FontPitch FontPitch=Variable!
end type

event clicked;close(parent)
end event

jspxnet 2007-03-08
  • 打赏
  • 举报
回复
高人继续
http://community.csdn.net/Expert/TopicView3.asp?id=5382888
ice1001 2007-03-08
  • 打赏
  • 举报
回复
up一下,看一下我们PB的高人们,呵呵
winterProgrammer 2007-03-08
  • 打赏
  • 举报
回复
up
kt563 2007-03-07
  • 打赏
  • 举报
回复
$PBExportHeader$f.srf
global type f from function_object
end type

forward prototypes
global function integer f (ref datawindow dw, long al_n, long al_x, long al_y)
end prototypes

global function integer f (ref datawindow dw, long al_n, long al_x, long al_y);string ls[]
long i[],ll0[],ll1[],j,ll_sum,k,l
j=1
ll0[j]=max(1,al_y - (al_x - j)*al_n)
ll1[j]=min(al_n,al_y / al_x )
i[j]=ll0[j]
ll_sum=i[j]
do while j > 0
if i[j]<=ll1[j] then
if j=al_x then
if ll_sum=al_y then
l=upperbound(ls)+1
ls[l]=''
for k=1 to al_x
ls[l]+='+'+ string(i[k])
next
ls[l]=mid(ls[l],2)
// messagebox('',ls[l])
end if
goto a
end if
ll0[j+1]=max(i[j]+1,al_y - ll_sum - (al_x - j -1) * al_n)
ll1[j+1]=min(al_n, (al_y - ll_sum) / (al_x -j) )
j++
i[j]=ll0[j]
ll_sum+=i[j]
continue
end if
a:
ll_sum -=i[j]
j --
if j>0 then
i[j]++
ll_sum++
end if
continue
loop
dw.object.#1.current=ls
messagebox('',upperbound(ls))
return 0

end function
hillhx 2007-03-07
  • 打赏
  • 举报
回复
我也乱写一个,不过是固定XY的,而且XY都不能太大

drop table #t1
go
drop table #t2
go
select top 0 cast(0 as int) as nu,row_id = identity(5)
into #t1

insert into #t1(nu)
select top 50 1
from sysobjects

create index t1_index_1 on #t1(row_id)
go
select a.row_id as a,b.row_id as b,c.row_id as c,d.row_id as d,e.row_id as e
into #t2
from #t1 a,#t1 b,#t1 c,#t1 d,#t1 e
where a.row_id < b.row_id
and b.row_id < c.row_id
and c.row_id < d.row_id
and d.row_id < e.row_id
and a.row_id+b.row_id+c.row_id+d.row_id+e.row_id = 100

go
select * from #t2
kt563 2007-03-07
  • 打赏
  • 举报
回复
厉害,标记下!
想到了用x 层for循环做,数据窗口再动态增加列...
比较郁闷,期待高手现身...
kt563 2007-03-07
  • 打赏
  • 举报
回复

数值在 1 - 50 之内的任意5个数之和为100
耗时:1154毫秒(三次平均)
总纪录:18583

测试机器配置:
intel(r)
(R)4 cpu 2.66GHz
AT/AT COMPATIBLE
260.084 KB RAM
sunday_hl 2007-03-07
  • 打赏
  • 举报
回复
测试的时候 首先:
声明2个全局数组变量:
String is_exp[] //存放所有的组合
Integer ii_number[] //在计算过程中,保存可能组和的临时组合

然后调用 :
f_get_choose(50,5,100) //需要的组合条件(n,x,y)
dw_1.Object.#1.Current = is_exp //把所有组合填入到DW


测试平台:
在dw_1中增加2个计算列,一个RowCount()放在脚底,
另一个describe('Evaluate("' + #1 + '",0)'),用于计算组和是否有错,
(前提,我的组合为“1 + 21 + 25 + 26 + 27”,同时在代码中对数字组合进行了排序,
所以可以使用Filter语句"GetRow() = 1 Or #1 <> #1[-1]"来查看是否有重复的组合。)

//====================================================================
// 事件: w_test_2.f_get_choose()
//--------------------------------------------------------------------
// 描述:
//--------------------------------------------------------------------
// 参数:
// value integer ai_n 需要从1开始到ai_n的区间
// value integer ai_x 个数
// value integer ai_y 和
//--------------------------------------------------------------------
// 返回: integer 共有的组合数
//--------------------------------------------------------------------
// 作者: Ran 日期: 2007年03月07日
//--------------------------------------------------------------------
// Copyright (c) 2002-2006 TRUEWAY(TM), All rights reserved.
//--------------------------------------------------------------------
// 修改历史:
//
//====================================================================

String ls_temp[]
Integer li_temp[]
//把全局数组清空
is_exp = ls_temp
ii_number = li_temp

//得到所有需要的组合
f_choose(1,ai_n,ai_x,ai_y,1)
//返回组合数
Return UpperBound(is_exp)





//====================================================================
// 事件: w_test_2.f_choose()
//--------------------------------------------------------------------
// 描述:
//--------------------------------------------------------------------
// 参数:
// value integer ai_begin 开区间
// value integer ai_end 闭区间
// value integer ai_x 个数
// value integer ai_y 和
// value integer ai_bound 记录当前组合数的数组下标
//--------------------------------------------------------------------
// 返回: integer
//--------------------------------------------------------------------
// 作者: Ran 日期: 2007年03月07日
//--------------------------------------------------------------------
// Copyright (c) 2002-2006 TRUEWAY(TM), All rights reserved.
//--------------------------------------------------------------------
// 修改历史:
//
//====================================================================

Integer i,j,li_mid,li_mid2,li_begin,li_end
String ls_exp
//返回 一点都没有
If ai_x <= 0 Then Return 0
//只有一个点,只要待求的和 在区间内,即满足条件
If ai_x = 1 Then
If ai_begin <= ai_y And ai_end >= ai_y Then
ls_exp = ""
ii_number[ai_bound] = ai_y
ls_exp = String(ii_number[1])
For i = 2 To UpperBound(ii_number)
ls_exp += " + " + String(ii_number[i])
Next
is_exp[UpperBound(is_exp) + 1] = ls_exp
Return 1
Else
Return 0
End If
End If
//2个点,如果其中的2个点 之和 等于 ai_y,即满足条件
If ai_x = 2 Then
li_mid = ai_y / 2
If li_mid < ai_begin Or li_mid >= ai_end Then Return 0
//找出 中间 临界点,进行左减右增
If Mod(ai_y,2) > 0 Then
li_begin = li_mid
li_end = li_mid + 1
Else
li_begin = li_mid - 1
li_end = li_mid + 1
End If
//循环找出所有的可能组和
Do
ls_exp = ""
ii_number[ai_bound] = li_begin
ii_number[ai_bound + 1] = li_end
ls_exp = String(ii_number[1])
For i = 2 To UpperBound(ii_number)
ls_exp += " + " + String(ii_number[i])
Next
is_exp[UpperBound(is_exp) + 1] = ls_exp

li_begin --
li_end ++
Loop Until li_begin < ai_begin Or li_end > ai_end
//
Return 1
End If
//找出 ai_x 个数组合中的临界点,
//临界点 即满足要求的组合 必须有一个数小于临界点和另一个数大于临界点
li_mid = ai_y / ai_x
li_mid2 = ai_x / 2
li_begin = li_mid - li_mid2
li_end = li_mid + li_mid2

If li_begin < ai_begin Or li_end > ai_end Then Return 0
//2层递归,找出所有可能的点
For i = ai_begin To li_begin
For j = li_end To ai_end
ii_number[ai_bound] = i
ii_number[ai_bound + ai_x - 1] = j
//对在满足临界点中的数进行 递归 运算,其中产生新的区间 组合个数 及新的和。
f_choose(i + 1,j - 1,ai_x - 2,ai_y - (i + j),ai_bound + 1 )
Next
Next

Return 1

//完毕。。。。。。。。。
sunday_hl 2007-03-07
  • 打赏
  • 举报
回复
支持搂主,先问一下,这个
“求数值在 1 - 50 之内的任意5个数之和为100”有多少种组合,

我写了一个 得到的组合数为18583种,是不是太多了点了哦!
freeliu 2007-03-07
  • 打赏
  • 举报
回复
为什么一回复,自动三次呀?
(接上面)
on w_calc_temp.create
this.sle_4=create sle_4
this.cb_3=create cb_3
this.dw_1=create dw_1
this.st_3=create st_3
this.st_2=create st_2
this.st_1=create st_1
this.sle_3=create sle_3
this.sle_2=create sle_2
this.sle_1=create sle_1
this.Control[]={this.sle_4,&
this.cb_3,&
this.dw_1,&
this.st_3,&
this.st_2,&
this.st_1,&
this.sle_3,&
this.sle_2,&
this.sle_1}
end on

on w_calc_temp.destroy
destroy(this.sle_4)
destroy(this.cb_3)
destroy(this.dw_1)
destroy(this.st_3)
destroy(this.st_2)
destroy(this.st_1)
destroy(this.sle_3)
destroy(this.sle_2)
destroy(this.sle_1)
end on

type sle_4 from singlelineedit within w_calc_temp
integer x = 192
integer y = 420
integer width = 402
integer height = 84
integer taborder = 30
integer textsize = -9
integer weight = 400
fontcharset fontcharset = gb2312charset!
fontpitch fontpitch = variable!
string facename = "宋体"
long textcolor = 33554432
string text = "none"
borderstyle borderstyle = stylelowered!
end type

type cb_3 from commandbutton within w_calc_temp
integer x = 311
integer y = 276
integer width = 402
integer height = 84
integer taborder = 20
integer textsize = -9
integer weight = 400
fontcharset fontcharset = gb2312charset!
fontpitch fontpitch = variable!
string facename = "宋体"
string text = "calc"
end type

event clicked;debugbreak()

ii_max_number = integer(sle_1.text)
ii_cnt_number = integer(sle_2.text)
ii_sum_number = integer(sle_3.text)

//parent.setredraw(false)
int li_empty[]

ii_number = li_empty

dw_1.reset()

ii_number[1] = 1
wf_calc(ii_number[1], ii_max_number, ii_cnt_number, ii_sum_number)
//parent.setredraw(true)

end event

type dw_1 from datawindow within w_calc_temp
integer x = 773
integer y = 36
integer width = 951
integer height = 1792
integer taborder = 40
string title = "none"
string dataobject = "d_result"
boolean hscrollbar = true
boolean vscrollbar = true
boolean livescroll = true
borderstyle borderstyle = stylelowered!
end type

type st_3 from statictext within w_calc_temp
integer x = 23
integer y = 188
integer width = 302
integer height = 48
integer textsize = -9
integer weight = 400
fontcharset fontcharset = gb2312charset!
fontpitch fontpitch = variable!
string facename = "宋体"
long textcolor = 33554432
long backcolor = 67108864
string text = "sum number"
boolean focusrectangle = false
end type

type st_2 from statictext within w_calc_temp
integer x = 23
integer y = 108
integer width = 302
integer height = 48
integer textsize = -9
integer weight = 400
fontcharset fontcharset = gb2312charset!
fontpitch fontpitch = variable!
string facename = "宋体"
long textcolor = 33554432
long backcolor = 67108864
string text = "cnt number"
boolean focusrectangle = false
end type

type st_1 from statictext within w_calc_temp
integer x = 23
integer y = 36
integer width = 302
integer height = 48
integer textsize = -9
integer weight = 400
fontcharset fontcharset = gb2312charset!
fontpitch fontpitch = variable!
string facename = "宋体"
long textcolor = 33554432
long backcolor = 67108864
string text = "max number"
boolean focusrectangle = false
end type

type sle_3 from singlelineedit within w_calc_temp
integer x = 325
integer y = 176
integer width = 402
integer height = 72
integer taborder = 30
integer textsize = -9
integer weight = 400
fontcharset fontcharset = gb2312charset!
fontpitch fontpitch = variable!
string facename = "宋体"
long textcolor = 33554432
string text = "20"
borderstyle borderstyle = stylelowered!
end type

type sle_2 from singlelineedit within w_calc_temp
integer x = 325
integer y = 104
integer width = 402
integer height = 72
integer taborder = 20
integer textsize = -9
integer weight = 400
fontcharset fontcharset = gb2312charset!
fontpitch fontpitch = variable!
string facename = "宋体"
long textcolor = 33554432
string text = "3"
borderstyle borderstyle = stylelowered!
end type

type sle_1 from singlelineedit within w_calc_temp
integer x = 325
integer y = 32
integer width = 402
integer height = 72
integer taborder = 10
integer textsize = -9
integer weight = 400
fontcharset fontcharset = gb2312charset!
fontpitch fontpitch = variable!
string facename = "宋体"
long textcolor = 33554432
string text = "20"
borderstyle borderstyle = stylelowered!
end type

freeliu 2007-03-07
  • 打赏
  • 举报
回复
为什么一回复,自动三次呀?
(接上面)
on w_calc_temp.create
this.sle_4=create sle_4
this.cb_3=create cb_3
this.dw_1=create dw_1
this.st_3=create st_3
this.st_2=create st_2
this.st_1=create st_1
this.sle_3=create sle_3
this.sle_2=create sle_2
this.sle_1=create sle_1
this.Control[]={this.sle_4,&
this.cb_3,&
this.dw_1,&
this.st_3,&
this.st_2,&
this.st_1,&
this.sle_3,&
this.sle_2,&
this.sle_1}
end on

on w_calc_temp.destroy
destroy(this.sle_4)
destroy(this.cb_3)
destroy(this.dw_1)
destroy(this.st_3)
destroy(this.st_2)
destroy(this.st_1)
destroy(this.sle_3)
destroy(this.sle_2)
destroy(this.sle_1)
end on

type sle_4 from singlelineedit within w_calc_temp
integer x = 192
integer y = 420
integer width = 402
integer height = 84
integer taborder = 30
integer textsize = -9
integer weight = 400
fontcharset fontcharset = gb2312charset!
fontpitch fontpitch = variable!
string facename = "宋体"
long textcolor = 33554432
string text = "none"
borderstyle borderstyle = stylelowered!
end type

type cb_3 from commandbutton within w_calc_temp
integer x = 311
integer y = 276
integer width = 402
integer height = 84
integer taborder = 20
integer textsize = -9
integer weight = 400
fontcharset fontcharset = gb2312charset!
fontpitch fontpitch = variable!
string facename = "宋体"
string text = "calc"
end type

event clicked;debugbreak()

ii_max_number = integer(sle_1.text)
ii_cnt_number = integer(sle_2.text)
ii_sum_number = integer(sle_3.text)

//parent.setredraw(false)
int li_empty[]

ii_number = li_empty

dw_1.reset()

ii_number[1] = 1
wf_calc(ii_number[1], ii_max_number, ii_cnt_number, ii_sum_number)
//parent.setredraw(true)

end event

type dw_1 from datawindow within w_calc_temp
integer x = 773
integer y = 36
integer width = 951
integer height = 1792
integer taborder = 40
string title = "none"
string dataobject = "d_result"
boolean hscrollbar = true
boolean vscrollbar = true
boolean livescroll = true
borderstyle borderstyle = stylelowered!
end type

type st_3 from statictext within w_calc_temp
integer x = 23
integer y = 188
integer width = 302
integer height = 48
integer textsize = -9
integer weight = 400
fontcharset fontcharset = gb2312charset!
fontpitch fontpitch = variable!
string facename = "宋体"
long textcolor = 33554432
long backcolor = 67108864
string text = "sum number"
boolean focusrectangle = false
end type

type st_2 from statictext within w_calc_temp
integer x = 23
integer y = 108
integer width = 302
integer height = 48
integer textsize = -9
integer weight = 400
fontcharset fontcharset = gb2312charset!
fontpitch fontpitch = variable!
string facename = "宋体"
long textcolor = 33554432
long backcolor = 67108864
string text = "cnt number"
boolean focusrectangle = false
end type

type st_1 from statictext within w_calc_temp
integer x = 23
integer y = 36
integer width = 302
integer height = 48
integer textsize = -9
integer weight = 400
fontcharset fontcharset = gb2312charset!
fontpitch fontpitch = variable!
string facename = "宋体"
long textcolor = 33554432
long backcolor = 67108864
string text = "max number"
boolean focusrectangle = false
end type

type sle_3 from singlelineedit within w_calc_temp
integer x = 325
integer y = 176
integer width = 402
integer height = 72
integer taborder = 30
integer textsize = -9
integer weight = 400
fontcharset fontcharset = gb2312charset!
fontpitch fontpitch = variable!
string facename = "宋体"
long textcolor = 33554432
string text = "20"
borderstyle borderstyle = stylelowered!
end type

type sle_2 from singlelineedit within w_calc_temp
integer x = 325
integer y = 104
integer width = 402
integer height = 72
integer taborder = 20
integer textsize = -9
integer weight = 400
fontcharset fontcharset = gb2312charset!
fontpitch fontpitch = variable!
string facename = "宋体"
long textcolor = 33554432
string text = "3"
borderstyle borderstyle = stylelowered!
end type

type sle_1 from singlelineedit within w_calc_temp
integer x = 325
integer y = 32
integer width = 402
integer height = 72
integer taborder = 10
integer textsize = -9
integer weight = 400
fontcharset fontcharset = gb2312charset!
fontpitch fontpitch = variable!
string facename = "宋体"
long textcolor = 33554432
string text = "20"
borderstyle borderstyle = stylelowered!
end type

iweb365 2007-03-07
  • 打赏
  • 举报
回复
Mark
freeliu 2007-03-07
  • 打赏
  • 举报
回复
刚才发的程序有些错误,现在重新发过。(不过还是没解决溢出的问题)
$PBExportHeader$w_calc_temp.srw
forward
global type w_calc_temp from window
end type
type sle_4 from singlelineedit within w_calc_temp
end type
type cb_3 from commandbutton within w_calc_temp
end type
type dw_1 from datawindow within w_calc_temp
end type
type st_3 from statictext within w_calc_temp
end type
type st_2 from statictext within w_calc_temp
end type
type st_1 from statictext within w_calc_temp
end type
type sle_3 from singlelineedit within w_calc_temp
end type
type sle_2 from singlelineedit within w_calc_temp
end type
type sle_1 from singlelineedit within w_calc_temp
end type
end forward

global type w_calc_temp from window
integer width = 1792
integer height = 2000
boolean titlebar = true
string title = "Untitled"
boolean controlmenu = true
boolean minbox = true
boolean maxbox = true
boolean resizable = true
long backcolor = 67108864
sle_4 sle_4
cb_3 cb_3
dw_1 dw_1
st_3 st_3
st_2 st_2
st_1 st_1
sle_3 sle_3
sle_2 sle_2
sle_1 sle_1
end type
global w_calc_temp w_calc_temp

type variables
int ii_number[]
int ii_max_number
int ii_cnt_number
int ii_sum_number

long ll_count

end variables
forward prototypes
public subroutine wf_calc (integer ai_min_number, integer ai_max_number, integer ai_cnt_number, integer ai_sum_number)
end prototypes

public subroutine wf_calc (integer ai_min_number, integer ai_max_number, integer ai_cnt_number, integer ai_sum_number);//函数功能:在ai_min_number~ai_max_number之间,任意ai_cnt_number个数的和为ai_sum_number
//参数: ai_min_number 最小数据
// ai_max_number 最大数据
// ai_cnt_number 参与计算的数据个数
// ai_sum_number 数据和
//返回值:实例变量数组ii_number[]
//说明:采用递归的方式

int i, j, k //计数器
int li_sum //用于保存数组各项的和
string ls_sum //用于保存输出的字符串
int li_upperbound //用于保存数组的上限

int li_empty[] //空数组,用于清空数组
int li_temp[] //保存数组的中间变量

int li_row

int li_sum_temp

//求已有数组上限
li_upperbound = upperbound(ii_number)

//求数组已有各项的和
for i = 1 to li_upperbound
li_sum = li_sum + ii_number[i]
next

//用于计算每一个数的取值范围
for i = 1 to ii_cnt_number - li_upperbound
li_sum_temp = li_sum_temp + i
next

if ai_cnt_number = 1 then //归结为最后一个数
for i = ai_min_number to ai_max_number
if i = ai_sum_number then
ii_number[li_upperbound] = i //数组最后一个元素赋值
//显示结果
ls_sum = string(ii_number[1])
for j = 2 to li_upperbound
ls_sum = ls_sum + '+' + string(ii_number[j])
next
ls_sum = ls_sum + '=' + string(ii_sum_number)

ll_count = ll_count + 1
sle_4.text = string(ll_count)
// 1. 向结果数据窗中插值
li_row = dw_1.insertrow(1)
dw_1.Object.result[li_row] = ls_sum

end if
next
// 2. 初始化数组
li_temp = ii_number //将数组数据保存到临时变量
ii_number = li_empty //清空数组,主要是恢复数组上限

for k = 1 to li_upperbound - 2
ii_number[k] = li_temp[k]
next
ii_number[li_upperbound - 1] = li_temp[li_upperbound - 1] + 1
wf_calc(ii_number[li_upperbound - 1], ii_max_number, ii_cnt_number - li_upperbound + 2, ii_sum_number - li_sum + li_temp[li_upperbound - 1])
else
if ii_number[li_upperbound] < int((ii_sum_number - li_sum_temp - li_sum + ii_number[li_upperbound]) / (ii_cnt_number - li_upperbound + 1)) + 1 then
ii_number[li_upperbound + 1] = ii_number[li_upperbound] + 1
wf_calc(ii_number[li_upperbound + 1], ii_max_number, ii_cnt_number - li_upperbound, ii_sum_number - li_sum)
else
if li_upperbound = 1 then return
// 2. 初始化数组
li_temp = ii_number //将数组数据保存到临时变量
ii_number = li_empty //清空数组,主要是恢复数组上限
for k = 1 to li_upperbound - 2
ii_number[k] = li_temp[k]
next
ii_number[li_upperbound - 1] = li_temp[li_upperbound - 1] + 1
wf_calc(ii_number[li_upperbound - 1], ii_max_number, ii_cnt_number - li_upperbound + 2, ii_sum_number - li_sum + li_temp[li_upperbound - 1])
end if
end if

end subroutine
freeliu 2007-03-07
  • 打赏
  • 举报
回复
刚才发的程序有些错误,现在重新发过。(不过还是没解决溢出的问题)
$PBExportHeader$w_calc_temp.srw
forward
global type w_calc_temp from window
end type
type sle_4 from singlelineedit within w_calc_temp
end type
type cb_3 from commandbutton within w_calc_temp
end type
type dw_1 from datawindow within w_calc_temp
end type
type st_3 from statictext within w_calc_temp
end type
type st_2 from statictext within w_calc_temp
end type
type st_1 from statictext within w_calc_temp
end type
type sle_3 from singlelineedit within w_calc_temp
end type
type sle_2 from singlelineedit within w_calc_temp
end type
type sle_1 from singlelineedit within w_calc_temp
end type
end forward

global type w_calc_temp from window
integer width = 1792
integer height = 2000
boolean titlebar = true
string title = "Untitled"
boolean controlmenu = true
boolean minbox = true
boolean maxbox = true
boolean resizable = true
long backcolor = 67108864
sle_4 sle_4
cb_3 cb_3
dw_1 dw_1
st_3 st_3
st_2 st_2
st_1 st_1
sle_3 sle_3
sle_2 sle_2
sle_1 sle_1
end type
global w_calc_temp w_calc_temp

type variables
int ii_number[]
int ii_max_number
int ii_cnt_number
int ii_sum_number

long ll_count

end variables
forward prototypes
public subroutine wf_calc (integer ai_min_number, integer ai_max_number, integer ai_cnt_number, integer ai_sum_number)
end prototypes

public subroutine wf_calc (integer ai_min_number, integer ai_max_number, integer ai_cnt_number, integer ai_sum_number);//函数功能:在ai_min_number~ai_max_number之间,任意ai_cnt_number个数的和为ai_sum_number
//参数: ai_min_number 最小数据
// ai_max_number 最大数据
// ai_cnt_number 参与计算的数据个数
// ai_sum_number 数据和
//返回值:实例变量数组ii_number[]
//说明:采用递归的方式

int i, j, k //计数器
int li_sum //用于保存数组各项的和
string ls_sum //用于保存输出的字符串
int li_upperbound //用于保存数组的上限

int li_empty[] //空数组,用于清空数组
int li_temp[] //保存数组的中间变量

int li_row

int li_sum_temp

//求已有数组上限
li_upperbound = upperbound(ii_number)

//求数组已有各项的和
for i = 1 to li_upperbound
li_sum = li_sum + ii_number[i]
next

//用于计算每一个数的取值范围
for i = 1 to ii_cnt_number - li_upperbound
li_sum_temp = li_sum_temp + i
next

if ai_cnt_number = 1 then //归结为最后一个数
for i = ai_min_number to ai_max_number
if i = ai_sum_number then
ii_number[li_upperbound] = i //数组最后一个元素赋值
//显示结果
ls_sum = string(ii_number[1])
for j = 2 to li_upperbound
ls_sum = ls_sum + '+' + string(ii_number[j])
next
ls_sum = ls_sum + '=' + string(ii_sum_number)

ll_count = ll_count + 1
sle_4.text = string(ll_count)
// 1. 向结果数据窗中插值
li_row = dw_1.insertrow(1)
dw_1.Object.result[li_row] = ls_sum

end if
next
// 2. 初始化数组
li_temp = ii_number //将数组数据保存到临时变量
ii_number = li_empty //清空数组,主要是恢复数组上限

for k = 1 to li_upperbound - 2
ii_number[k] = li_temp[k]
next
ii_number[li_upperbound - 1] = li_temp[li_upperbound - 1] + 1
wf_calc(ii_number[li_upperbound - 1], ii_max_number, ii_cnt_number - li_upperbound + 2, ii_sum_number - li_sum + li_temp[li_upperbound - 1])
else
if ii_number[li_upperbound] < int((ii_sum_number - li_sum_temp - li_sum + ii_number[li_upperbound]) / (ii_cnt_number - li_upperbound + 1)) + 1 then
ii_number[li_upperbound + 1] = ii_number[li_upperbound] + 1
wf_calc(ii_number[li_upperbound + 1], ii_max_number, ii_cnt_number - li_upperbound, ii_sum_number - li_sum)
else
if li_upperbound = 1 then return
// 2. 初始化数组
li_temp = ii_number //将数组数据保存到临时变量
ii_number = li_empty //清空数组,主要是恢复数组上限
for k = 1 to li_upperbound - 2
ii_number[k] = li_temp[k]
next
ii_number[li_upperbound - 1] = li_temp[li_upperbound - 1] + 1
wf_calc(ii_number[li_upperbound - 1], ii_max_number, ii_cnt_number - li_upperbound + 2, ii_sum_number - li_sum + li_temp[li_upperbound - 1])
end if
end if

end subroutine
freeliu 2007-03-07
  • 打赏
  • 举报
回复
刚才发的程序有些错误,现在重新发过。(不过还是没解决溢出的问题)
$PBExportHeader$w_calc_temp.srw
forward
global type w_calc_temp from window
end type
type sle_4 from singlelineedit within w_calc_temp
end type
type cb_3 from commandbutton within w_calc_temp
end type
type dw_1 from datawindow within w_calc_temp
end type
type st_3 from statictext within w_calc_temp
end type
type st_2 from statictext within w_calc_temp
end type
type st_1 from statictext within w_calc_temp
end type
type sle_3 from singlelineedit within w_calc_temp
end type
type sle_2 from singlelineedit within w_calc_temp
end type
type sle_1 from singlelineedit within w_calc_temp
end type
end forward

global type w_calc_temp from window
integer width = 1792
integer height = 2000
boolean titlebar = true
string title = "Untitled"
boolean controlmenu = true
boolean minbox = true
boolean maxbox = true
boolean resizable = true
long backcolor = 67108864
sle_4 sle_4
cb_3 cb_3
dw_1 dw_1
st_3 st_3
st_2 st_2
st_1 st_1
sle_3 sle_3
sle_2 sle_2
sle_1 sle_1
end type
global w_calc_temp w_calc_temp

type variables
int ii_number[]
int ii_max_number
int ii_cnt_number
int ii_sum_number

long ll_count

end variables
forward prototypes
public subroutine wf_calc (integer ai_min_number, integer ai_max_number, integer ai_cnt_number, integer ai_sum_number)
end prototypes

public subroutine wf_calc (integer ai_min_number, integer ai_max_number, integer ai_cnt_number, integer ai_sum_number);//函数功能:在ai_min_number~ai_max_number之间,任意ai_cnt_number个数的和为ai_sum_number
//参数: ai_min_number 最小数据
// ai_max_number 最大数据
// ai_cnt_number 参与计算的数据个数
// ai_sum_number 数据和
//返回值:实例变量数组ii_number[]
//说明:采用递归的方式

int i, j, k //计数器
int li_sum //用于保存数组各项的和
string ls_sum //用于保存输出的字符串
int li_upperbound //用于保存数组的上限

int li_empty[] //空数组,用于清空数组
int li_temp[] //保存数组的中间变量

int li_row

int li_sum_temp

//求已有数组上限
li_upperbound = upperbound(ii_number)

//求数组已有各项的和
for i = 1 to li_upperbound
li_sum = li_sum + ii_number[i]
next

//用于计算每一个数的取值范围
for i = 1 to ii_cnt_number - li_upperbound
li_sum_temp = li_sum_temp + i
next

if ai_cnt_number = 1 then //归结为最后一个数
for i = ai_min_number to ai_max_number
if i = ai_sum_number then
ii_number[li_upperbound] = i //数组最后一个元素赋值
//显示结果
ls_sum = string(ii_number[1])
for j = 2 to li_upperbound
ls_sum = ls_sum + '+' + string(ii_number[j])
next
ls_sum = ls_sum + '=' + string(ii_sum_number)

ll_count = ll_count + 1
sle_4.text = string(ll_count)
// 1. 向结果数据窗中插值
li_row = dw_1.insertrow(1)
dw_1.Object.result[li_row] = ls_sum

end if
next
// 2. 初始化数组
li_temp = ii_number //将数组数据保存到临时变量
ii_number = li_empty //清空数组,主要是恢复数组上限

for k = 1 to li_upperbound - 2
ii_number[k] = li_temp[k]
next
ii_number[li_upperbound - 1] = li_temp[li_upperbound - 1] + 1
wf_calc(ii_number[li_upperbound - 1], ii_max_number, ii_cnt_number - li_upperbound + 2, ii_sum_number - li_sum + li_temp[li_upperbound - 1])
else
if ii_number[li_upperbound] < int((ii_sum_number - li_sum_temp - li_sum + ii_number[li_upperbound]) / (ii_cnt_number - li_upperbound + 1)) + 1 then
ii_number[li_upperbound + 1] = ii_number[li_upperbound] + 1
wf_calc(ii_number[li_upperbound + 1], ii_max_number, ii_cnt_number - li_upperbound, ii_sum_number - li_sum)
else
if li_upperbound = 1 then return
// 2. 初始化数组
li_temp = ii_number //将数组数据保存到临时变量
ii_number = li_empty //清空数组,主要是恢复数组上限
for k = 1 to li_upperbound - 2
ii_number[k] = li_temp[k]
next
ii_number[li_upperbound - 1] = li_temp[li_upperbound - 1] + 1
wf_calc(ii_number[li_upperbound - 1], ii_max_number, ii_cnt_number - li_upperbound + 2, ii_sum_number - li_sum + li_temp[li_upperbound - 1])
end if
end if

end subroutine
iweb365 2007-03-07
  • 打赏
  • 举报
回复
d
加载更多回复(35)

1,075

社区成员

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

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