主頁(yè) > 知識(shí)庫(kù) > shell實(shí)現(xiàn)FizzBuzzWhizz問(wèn)題示例(拉勾網(wǎng)面試題)

shell實(shí)現(xiàn)FizzBuzzWhizz問(wèn)題示例(拉勾網(wǎng)面試題)

熱門(mén)標(biāo)簽:陜西電銷卡外呼系統(tǒng)怎么安裝 東莞電銷機(jī)器人價(jià)格一覽表 旅游地圖標(biāo)注大全 地圖標(biāo)注超出范圍怎么辦 excel地址地圖標(biāo)注 百度地圖的地圖標(biāo)注 佛山高德地圖標(biāo)注中心 百度地圖標(biāo)注圖標(biāo)更換 杭州機(jī)器人外呼系統(tǒng)

試題: https://www.jinshuju.net/f/EGQL3D

語(yǔ)言: Shell (Bash)
運(yùn)行方式:
sh num-game.sh 數(shù)字1 數(shù)字2 數(shù)字3
如果不想使用傳遞數(shù)字的方式, 可以修改 num-game.sh 第 9 行, 將
NUM=$*
改為
NUM='數(shù)字1 數(shù)字2 數(shù)字3'
然后直接運(yùn)行 sh num-game.sh 即可

復(fù)制代碼 代碼如下:

#!/bin/bash

## Author : TaxKiz
## Email  : taxkiz@gmail.com

export PATH='/bin:/sbin:/usr/bin:/usr/sbin'

## NUM='3 5 7'
NUM=$*

## 檢查輸入的數(shù)字個(gè)數(shù)是否為 3 個(gè)
function CT () {
    [ $( echo $* | sed 's/ /\n/g' | wc -l ) != '3' ] echo " Please Enter 3 Number ! " exit 1
}

CT $NUM

## 個(gè)位數(shù)列表
NT='1/2/3/4/5/6/7/8/9'

## 檢查輸入的數(shù)字是否為個(gè)位數(shù)
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

## 判斷是否有重復(fù)的數(shù)字
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

您可能感興趣的文章:
  • java實(shí)現(xiàn)拉鉤網(wǎng)上的FizzBuzzWhizz問(wèn)題示例
  • 使用python實(shí)現(xiàn)拉鉤網(wǎng)上的FizzBuzzWhizz問(wèn)題示例
  • 拉鉤網(wǎng)java筆試題分享

標(biāo)簽:青島 朝陽(yáng) 通遼 雅安 南充 延邊 隨州 西藏

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《shell實(shí)現(xiàn)FizzBuzzWhizz問(wèn)題示例(拉勾網(wǎng)面試題)》,本文關(guān)鍵詞  shell,實(shí)現(xiàn),FizzBuzzWhizz,問(wèn)題,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《shell實(shí)現(xiàn)FizzBuzzWhizz問(wèn)題示例(拉勾網(wǎng)面試題)》相關(guān)的同類信息!
  • 本頁(yè)收集關(guān)于shell實(shí)現(xiàn)FizzBuzzWhizz問(wèn)題示例(拉勾網(wǎng)面試題)的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章