Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "fmt"
- "bufio"
- "os"
- )
- func main() {
- scanner := bufio.NewScanner(os.Stdin)
- scanner.Scan()
- book := scanner.Text()
- counter := 0
- scanner.Scan()
- input := scanner.Text()
- for input != "NoMoreBooks" && input != book {
- counter++
- scanner.Scan()
- input = scanner.Text()
- }
- if input == book {
- fmt.Printf("You checked %d books and found it.\n", counter)
- } else {
- fmt.Println("The book you search is not here!")
- fmt.Printf("You checked %d books.\n", counter)
- }
- }
- ИЛИ:
- package main
- import (
- "fmt"
- "bufio"
- "os"
- )
- func main() {
- scanner := bufio.NewScanner(os.Stdin)
- scanner.Scan()
- book := scanner.Text()
- for counter := 0; ; counter++ {
- scanner.Scan()
- input := scanner.Text()
- if input == book {
- fmt.Printf("You checked %d books and found it.\n", counter)
- break
- }
- if input == "NoMoreBooks" {
- fmt.Printf("The book you search is not here!\nYou checked %d books.\n", counter)
- break
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement