Advertisement
Spocoman

01. Old Books

Sep 22nd, 2024
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.91 KB | None | 0 0
  1. package main
  2.  
  3. import "fmt"
  4.  
  5. func main() {
  6.     var book, input string
  7.     fmt.Scanln(&book)
  8.    
  9.     for counter := 0; ; counter++ {
  10.         fmt.Scanln(&input)
  11.         if input == book {
  12.             fmt.Printf("You checked %d books and found it.\n", counter)
  13.             break
  14.         }
  15.         if input == "NoMoreBooks" {
  16.             fmt.Printf("The book you search is not here!\nYou checked %d books.\n", counter)
  17.             break
  18.         }
  19.     }
  20. }
  21.  
  22. ИЛИ:
  23.  
  24. package main
  25.  
  26. import "fmt"
  27.  
  28. func main() {
  29.     var book, input string
  30.     fmt.Scanln(&book)
  31.    
  32.     var counter = -1
  33.    
  34.     for ; input != book && input != "NoMoreBooks"; {
  35.         fmt.Scanln(&input)
  36.         counter++
  37.     }
  38.  
  39.     if input == book {
  40.         fmt.Printf("You checked %d books and found it.\n", counter)
  41.     } else {
  42.         fmt.Printf("The book you search is not here!\nYou checked %d books.\n", counter)
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement