Advertisement
Spocoman

The Most Powerful Word

Oct 13th, 2024
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.84 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.     "bufio"
  5.     "fmt"
  6.     "os"
  7.     "strings"
  8. )
  9.  
  10. func main() {
  11.     scanner := bufio.NewScanner(os.Stdin)
  12.     scanner.Scan()
  13.     word := scanner.Text()
  14.  
  15.     vowels := "aeiouyAEIOUY"
  16.     strongWord := ""
  17.     strongSum := 0.0
  18.  
  19.     for word != "End of words" {
  20.         wordSum := 0.0
  21.         for i := 0; i < len(word); i++ {
  22.             wordSum += float64(int(word[i]))
  23.         }
  24.  
  25.         if strings.Contains(vowels, string(word[0])) {
  26.             wordSum *= float64(len(word))
  27.         } else {
  28.             wordSum /= float64(len(word))
  29.         }
  30.  
  31.         if wordSum > strongSum {
  32.             strongWord = word
  33.             strongSum = wordSum
  34.         }
  35.         scanner.Scan()
  36.         word = scanner.Text()
  37.     }
  38.  
  39.     fmt.Printf("The most powerful word is %s - %d", strongWord, int(strongSum))
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement