Advertisement
Spocoman

Old Books

Oct 11th, 2024
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 1.17 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.   "fmt"
  5.   "bufio"
  6.   "os"
  7. )
  8.  
  9. func main() {
  10.     scanner := bufio.NewScanner(os.Stdin)
  11.     scanner.Scan()
  12.     book := scanner.Text()
  13.    
  14.     counter := 0
  15.    
  16.     scanner.Scan()
  17.     input := scanner.Text()
  18.  
  19.     for input != "NoMoreBooks" && input != book {
  20.         counter++
  21.         scanner.Scan()
  22.         input = scanner.Text()
  23.     }
  24.  
  25.     if input == book {
  26.         fmt.Printf("You checked %d books and found it.\n", counter)
  27.     } else {
  28.         fmt.Println("The book you search is not here!")
  29.         fmt.Printf("You checked %d books.\n", counter)
  30.     }
  31. }
  32.  
  33. ИЛИ:
  34.  
  35. package main
  36.  
  37. import (
  38.   "fmt"
  39.   "bufio"
  40.   "os"
  41. )
  42.  
  43. func main() {
  44.     scanner := bufio.NewScanner(os.Stdin)
  45.     scanner.Scan()
  46.     book := scanner.Text()
  47.    
  48.     for counter := 0; ; counter++ {
  49.         scanner.Scan()
  50.         input := scanner.Text()
  51.         if input == book {
  52.             fmt.Printf("You checked %d books and found it.\n", counter)
  53.             break
  54.         }
  55.         if input == "NoMoreBooks" {
  56.             fmt.Printf("The book you search is not here!\nYou checked %d books.\n", counter)
  57.             break
  58.         }
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement