Skip to content

Instantly share code, notes, and snippets.

@gerep
Last active March 6, 2017 19:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gerep/d79f0751aaf18a4962938703c370f076 to your computer and use it in GitHub Desktop.
Save gerep/d79f0751aaf18a4962938703c370f076 to your computer and use it in GitHub Desktop.
package main
import (
"bufio"
"fmt"
"os"
"strconv"
"strings"
)
func main() {
// Read numbers list from Stdin
scanner := bufio.NewScanner(os.Stdin)
var lines [2]string
var count int
for scanner.Scan() {
lines[count] = scanner.Text()
count++
}
if err := scanner.Err(); err != nil {
panic(err)
}
numbers := strings.Split(string(lines[0]), " ")
word := strings.Split(string(lines[1]), "")
alphabet := strings.Split("a b c d e f g h i j k l m n o p q r s t u v w x y z", " ")
// Convert numbers from string to int into the array
intNumbersList := make([]int, 26)
for x := 0; x < 26; x++ {
i, err := strconv.Atoi(numbers[x])
if err != nil {
panic(err)
}
intNumbersList[x] = i
}
higher := 0
for _, w := range word {
for k, a := range alphabet {
if w == a {
if higher < intNumbersList[k] {
higher = intNumbersList[k]
}
}
}
}
fmt.Println(higher * len(word))
}
@gerep
Copy link
Author

gerep commented Mar 1, 2017

This code is still failing for this input:

6 3 4 4 6 4 5 3 4 3 6 5 4 6 7 1 3 4 2 5 6 1 5 1 7 2
nrdyluacvr

It is expecting the output 70 but it is returning 60

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment