试题: https://www.jinshuju.net/f/EGQL3D
语言: Shell (Bash)
运行方式:
sh num-game.sh 数字1 数字2 数字3
如果不想使用传递数字的方式, 可以修改 num-game.sh 第 9 行, 将
NUM=$*
改为
NUM='数字1 数字2 数字3'
然后直接运行 sh num-game.sh 即可
复制代码 代码如下:
#!/bin/bash
## Author : TaxKiz
## Email : taxkiz@gmail.com
export PATH='/bin:/sbin:/usr/bin:/usr/sbin'
## NUM='3 5 7'
NUM=$*
## 检查输入的数字个数是否为 3 个
function CT () {
[ $( echo $* | sed 's/ /\n/g' | wc -l ) != '3' ] && echo " Please Enter 3 Number ! " && exit 1
}
CT $NUM
## 个位数列表
NT='1/2/3/4/5/6/7/8/9'
## 检查输入的数字是否为个位数
function CK () {
for num in $*
do
[ $num == '0' ] && echo "Error Number '$num'" && exit 2
echo $NT | grep "\b$num\b" > /dev/null 2>&1
[ $? != '0' ] && echo "$num is not a single digit" && exit 3
done
}
CK $NUM
## 判断是否有重复的数字
function SN () {
if [ $1 == $2 ] || [ $1 == $3 ] || [ $2 == $3 ]; then
echo "ERROR! There have same number : '$*'"
exit 4
fi
}
SN $NUM
## 大喊一声
function GO () {
A1=$1
A2=$2
A3=$3
T1=$(( $1 * $2 ))
T2=$(( $1 * $3 ))
T3=$(( $2 * $3 ))
TA=$(( $1 * $2 * $3 ))
for num in {1..100}
do
echo $num | grep $A1 > /dev/null 2>&1
[ $? == '0' ] && echo 'Fizz' && continue
echo "scale=2; $num/$TA" | bc | grep 00 > /dev/null 2>&1
[ $? == '0' ] && echo 'FizzBuzzWhizz' && continue
echo "scale=2; $num/$T1" | bc | grep 00 > /dev/null 2>&1
[ $? == '0' ] && echo 'FizzBuzz' && continue
echo "scale=2; $num/$T2" | bc | grep 00 > /dev/null 2>&1
[ $? == '0' ] && echo 'BuzzWhizz' && continue
echo "scale=2; $num/$T3" | bc | grep 00 > /dev/null 2>&1
[ $? == '0' ] && echo 'FizzWhizz' && continue
echo "scale=2; $num/$A1" | bc | grep 00 > /dev/null 2>&1
[ $? == '0' ] && echo 'Fizz' && continue
echo "scale=2; $num/$A2" | bc | grep 00 > /dev/null 2>&1
[ $? == '0' ] && echo 'Buzz' && continue
echo "scale=2; $num/$A3" | bc | grep 00 > /dev/null 2>&1
[ $? == '0' ] && echo 'Whizz' && continue
echo $num
done
}
GO $NUM
更新日志
- 小骆驼-《草原狼2(蓝光CD)》[原抓WAV+CUE]
- 群星《欢迎来到我身边 电影原声专辑》[320K/MP3][105.02MB]
- 群星《欢迎来到我身边 电影原声专辑》[FLAC/分轨][480.9MB]
- 雷婷《梦里蓝天HQⅡ》 2023头版限量编号低速原抓[WAV+CUE][463M]
- 群星《2024好听新歌42》AI调整音效【WAV分轨】
- 王思雨-《思念陪着鸿雁飞》WAV
- 王思雨《喜马拉雅HQ》头版限量编号[WAV+CUE]
- 李健《无时无刻》[WAV+CUE][590M]
- 陈奕迅《酝酿》[WAV分轨][502M]
- 卓依婷《化蝶》2CD[WAV+CUE][1.1G]
- 群星《吉他王(黑胶CD)》[WAV+CUE]
- 齐秦《穿乐(穿越)》[WAV+CUE]
- 发烧珍品《数位CD音响测试-动向效果(九)》【WAV+CUE】
- 邝美云《邝美云精装歌集》[DSF][1.6G]
- 吕方《爱一回伤一回》[WAV+CUE][454M]