Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
13
Task/Count-the-coins/UNIX-Shell/count-the-coins-1.sh
Normal file
13
Task/Count-the-coins/UNIX-Shell/count-the-coins-1.sh
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
function count_change {
|
||||
local -i amount=$1 coin j
|
||||
local ways=(1)
|
||||
shift
|
||||
for coin; do
|
||||
for (( j=coin; j <= amount; j++ )); do
|
||||
let ways[j]=${ways[j]:-0}+${ways[j-coin]:-0}
|
||||
done
|
||||
done
|
||||
echo "${ways[amount]}"
|
||||
}
|
||||
count_change 100 25 10 5 1
|
||||
count_change 100000 100 50 25 10 5 1
|
||||
14
Task/Count-the-coins/UNIX-Shell/count-the-coins-2.sh
Normal file
14
Task/Count-the-coins/UNIX-Shell/count-the-coins-2.sh
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
function count_change {
|
||||
typeset -i amount=$1 coin j
|
||||
typeset ways
|
||||
set -A ways 1
|
||||
shift
|
||||
for coin; do
|
||||
for (( j=coin; j <= amount; j++ )); do
|
||||
let ways[j]=${ways[j]:-0}+${ways[j-coin]:-0}
|
||||
done
|
||||
done
|
||||
echo "${ways[amount]}"
|
||||
}
|
||||
count_change 100 25 10 5 1
|
||||
count_change 100000 100 50 25 10 5 1
|
||||
16
Task/Count-the-coins/UNIX-Shell/count-the-coins-3.sh
Normal file
16
Task/Count-the-coins/UNIX-Shell/count-the-coins-3.sh
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
function count_change {
|
||||
typeset -i amount=$1 coin j
|
||||
typeset ways
|
||||
set -A ways 1
|
||||
shift
|
||||
for coin; do
|
||||
let j=coin
|
||||
while (( j <= amount )); do
|
||||
let ways[j]=${ways[j]:-0}+${ways[j-coin]:-0}
|
||||
let j+=1
|
||||
done
|
||||
done
|
||||
echo "${ways[amount]}"
|
||||
}
|
||||
count_change 100 25 10 5 1
|
||||
# (optional task exceeds a subscript limit in ksh88)
|
||||
15
Task/Count-the-coins/UNIX-Shell/count-the-coins-4.sh
Normal file
15
Task/Count-the-coins/UNIX-Shell/count-the-coins-4.sh
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
if [ $# -lt 2 ]; then
|
||||
set ${1-100} 25 10 5 1
|
||||
fi
|
||||
amount=$1
|
||||
shift
|
||||
ways_0=1
|
||||
for coin in "$@"; do
|
||||
j=$coin
|
||||
while [ $j -le $amount ]; do
|
||||
d=`expr $j - $coin`
|
||||
eval "ways_$j=\`expr \${ways_$j-0} + \${ways_$d-0}\`"
|
||||
j=`expr $j + 1`
|
||||
done
|
||||
done
|
||||
eval "echo \$ways_$amount"
|
||||
Loading…
Add table
Add a link
Reference in a new issue