Last active
March 6, 2017 19:09
-
-
Save gerep/d79f0751aaf18a4962938703c370f076 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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)) | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This code is still failing for this input:
It is expecting the output
70but it is returning60