Guess the number

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Guess the number相关的知识,希望对你有一定的参考价值。

#! /bin/bash
total=0
num=$((RANDOM%41))
pear(){
read -p "please input number:" a
expr $a + 1 &> /dev/null
if [ $? -ne 0 ];then
echo "please input number;"
pear
fi
}

guess(){
((total++))
if [ $a -eq $num ];then
echo "you guess is rigth."
if [ $total -eq 3 ];then
echo "less than three times."
elif [ $total -gt 3 -a $total -lt 5 ];then
echo " less 5"
elif [ $total -eq 6 ];then
echo "it‘s many times."
fi
exit 0
elif [ $a -gt $num ];then
echo "$a is bigger than num"
pear
elif [ $a -lt $num ];then
echo "$a is less than num"
pear
fi
}

main(){
pear
while true;do
guess
done
}

以上是关于Guess the number的主要内容,如果未能解决你的问题,请参考以下文章

Leetcode 843. Guess the Word

Guess the number

1562 Guess the number

攻防世界 reverse Guess-the-Number

hdu 5981 Guess the number

CodeForces 618B Guess the Permutation