Advertisement
Spocoman

Favorite Movie

Oct 9th, 2024
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.98 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.     "bufio"
  5.     "fmt"
  6.     "os"
  7. )
  8.  
  9. func main() {
  10.     scanner := bufio.NewScanner(os.Stdin)
  11.     scanner.Scan()
  12.     movie := scanner.Text()
  13.    
  14.     var bestMovie string
  15.     var counter, bestAscii int
  16.  
  17.     for movie != "STOP" && counter < 7 {
  18.         currentAscii := 0
  19.         for j := 0; j < len(movie); j++ {
  20.             currentAscii += int(movie[j])
  21.             if int(movie[j]) > 96 && int(movie[j]) < 123 {
  22.                 currentAscii -= len(movie) * 2
  23.             } else if int(movie[j]) > 64 && int(movie[j]) < 91 {
  24.                 currentAscii -= len(movie)
  25.             }
  26.         }
  27.         if currentAscii > bestAscii {
  28.             bestAscii = currentAscii
  29.             bestMovie = movie
  30.         }
  31.         counter++
  32.         scanner.Scan()
  33.         movie = scanner.Text()
  34.     }
  35.  
  36.     if counter == 7 {
  37.         fmt.Println("The limit is reached.")
  38.     }
  39.     fmt.Printf("The best movie for you is %s with %d ASCII sum.", bestMovie, bestAscii)
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement