Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
70
Task/Combinations/Action-/combinations.action
Normal file
70
Task/Combinations/Action-/combinations.action
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
PROC PrintComb(BYTE ARRAY c BYTE len)
|
||||
BYTE i
|
||||
|
||||
Put('()
|
||||
FOR i=0 TO len-1
|
||||
DO
|
||||
IF i>0 THEN Put(',) FI
|
||||
PrintB(c(i))
|
||||
OD
|
||||
Put(')) PutE()
|
||||
RETURN
|
||||
|
||||
BYTE FUNC Increasing(BYTE ARRAY c BYTE len)
|
||||
BYTE i
|
||||
|
||||
IF len<2 THEN RETURN (1) FI
|
||||
|
||||
FOR i=0 TO len-2
|
||||
DO
|
||||
IF c(i)>=c(i+1) THEN
|
||||
RETURN (0)
|
||||
FI
|
||||
OD
|
||||
RETURN (1)
|
||||
|
||||
BYTE FUNC NextComb(BYTE ARRAY c BYTE n,k)
|
||||
INT pos,i
|
||||
|
||||
DO
|
||||
pos=k-1
|
||||
DO
|
||||
c(pos)==+1
|
||||
IF c(pos)<n THEN
|
||||
EXIT
|
||||
ELSE
|
||||
pos==-1
|
||||
IF pos<0 THEN RETURN (0) FI
|
||||
FI
|
||||
FOR i=pos+1 TO k-1
|
||||
DO
|
||||
c(i)=c(pos)
|
||||
OD
|
||||
OD
|
||||
UNTIL Increasing(c,k)
|
||||
OD
|
||||
RETURN (1)
|
||||
|
||||
PROC Comb(BYTE n,k)
|
||||
BYTE ARRAY c(10)
|
||||
BYTE i
|
||||
|
||||
IF k>n THEN
|
||||
Print("Error! k is greater than n.")
|
||||
Break()
|
||||
FI
|
||||
|
||||
FOR i=0 TO k-1
|
||||
DO
|
||||
c(i)=i
|
||||
OD
|
||||
|
||||
DO
|
||||
PrintComb(c,k)
|
||||
UNTIL NextComb(c,n,k)=0
|
||||
OD
|
||||
RETURN
|
||||
|
||||
PROC Main()
|
||||
Comb(5,3)
|
||||
RETURN
|
||||
Loading…
Add table
Add a link
Reference in a new issue