Created
May 16, 2015 12:02
-
-
Save iporsut/39d0243be781fe40d490 to your computer and use it in GitHub Desktop.
Alien Language Go
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 ( | |
| "bytes" | |
| "fmt" | |
| "strings" | |
| ) | |
| func main() { | |
| // Read first line | |
| L := 0 | |
| D := 0 | |
| N := 0 | |
| fmt.Scanf("%d %d %d", &L, &D, &N) | |
| dict := "" | |
| dicts := make([]string, 0, D) | |
| // Read Dict | |
| for i := 0; i < D; i++ { | |
| fmt.Scanf("%s", &dict) | |
| dicts = append(dicts, dict) | |
| } | |
| tokensList := make([][]string, 0, N) | |
| // Read Token | |
| for i := 0; i < N; i++ { | |
| tokens := make([]string, 0, L) | |
| inGroup := false | |
| token := "" | |
| fmt.Scanf("%s", &token) | |
| w := new(bytes.Buffer) | |
| for _, s := range token { | |
| t := string(s) | |
| switch { | |
| case !inGroup && t == "(": | |
| w = new(bytes.Buffer) | |
| inGroup = true | |
| continue | |
| case !inGroup && t != "(": | |
| w = new(bytes.Buffer) | |
| tokens = append(tokens, t) | |
| inGroup = false | |
| continue | |
| case inGroup && t != ")": | |
| w.WriteString(t) | |
| inGroup = true | |
| continue | |
| case inGroup && t == ")": | |
| tokens = append(tokens, w.String()) | |
| w = new(bytes.Buffer) | |
| inGroup = false | |
| continue | |
| } | |
| } | |
| tokensList = append(tokensList, tokens) | |
| } | |
| // Check Token | |
| for k, tokens := range tokensList { | |
| count := 0 | |
| NextWord: | |
| for _, word := range dicts { | |
| for j, w := range word { | |
| if !strings.Contains(tokens[j], string(w)) { | |
| continue NextWord | |
| } | |
| } | |
| count++ | |
| } | |
| fmt.Printf("Case #%d: %d\n", k+1, count) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment