Last active
June 23, 2022 06:26
-
-
Save VTRyo/4f06f9d146b542a0f6398a9f91918de3 to your computer and use it in GitHub Desktop.
10分で書いたFizzBuzzですわよ〜〜
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"bufio" | |
"fmt" | |
"math/rand" | |
"os" | |
"strconv" | |
"time" | |
) | |
func random_sentence() string { | |
words := []string{"ですのよ〜!", "ですわ〜"} | |
rand.Seed(time.Now().UnixNano()) | |
num := rand.Intn(len(words)) | |
return words[num] | |
} | |
func main() { | |
fmt.Print("お数字をいれてほしいですわ> ") | |
scanner := bufio.NewScanner(os.Stdin) | |
scanner.Scan() | |
in := scanner.Text() | |
fmt.Printf("%vをいれましたわ〜\n", in) | |
fmt.Print("お数字をいれてほしいですわ> ") | |
scanner2 := bufio.NewScanner(os.Stdin) | |
scanner2.Scan() | |
in2 := scanner2.Text() | |
fmt.Printf("%vをいれましたわ〜\n", in2) | |
fmt.Printf("%vから%vまでの数字をご用意しましたわ\n", in, in2) | |
fmt.Println("お数字が3の倍数でしたらFizzを表示しますわ") | |
fmt.Println("お数字が5の倍数でしたらBuzzを表示しますわ") | |
fmt.Println("お数字が15の倍数でしたらFizzBuzzを表示しますわ") | |
var startInt int | |
var endInt int | |
startInt, _ = strconv.Atoi(in) | |
endInt, _ = strconv.Atoi(in2) | |
i := startInt | |
for i < endInt+1 { | |
switch { | |
case i%15 == 0: | |
fmt.Printf("FIZZBUZZ%s\n", random_sentence()) | |
case i%3 == 0: | |
fmt.Printf("FIZZ%s\n", random_sentence()) | |
case i%5 == 0: | |
fmt.Printf("BUZZ%s\n", random_sentence()) | |
default: | |
fmt.Println(i) | |
} | |
i++ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment