Created
August 19, 2015 15:40
-
-
Save angch/ca100cbd197cf90e38bd 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" | |
"bytes" | |
"fmt" | |
"io" | |
"regexp" | |
"strconv" | |
) | |
func doScore(input io.Reader) { | |
scanner := bufio.NewScanner(input) // was os.Stdin | |
scanner.Scan() | |
ncols, _ := strconv.Atoi(scanner.Text()) | |
// Yeah, we don't care cgpa, exp or score, really. Them just numbers | |
attributes := make([][]int, 3) | |
re, _ := regexp.Compile("(?i)[0-9]+") | |
for attrNum := 0; attrNum < 3; attrNum++ { | |
attributes[attrNum] = make([]int, ncols) | |
scanner.Scan() | |
scannedText := scanner.Text() | |
words := re.FindAllStringSubmatch(scannedText, -1) | |
for k, word := range words { | |
attributes[attrNum][k], _ = strconv.Atoi(word[0]) | |
} | |
} | |
removed := 0 | |
next: | |
for i := 0; i < ncols; i++ { | |
for j := 0; j < ncols; j++ { | |
mediocreCount := 0 | |
for k := 0; k < 3; k++ { | |
if attributes[k][i] < attributes[k][j] { | |
mediocreCount++ | |
} | |
} | |
if mediocreCount >= 3 { | |
removed++ | |
continue next | |
} | |
} | |
} | |
fmt.Println(removed) | |
} | |
func main() { | |
input := bytes.NewBufferString(`3 | |
1 4 2 | |
4 3 2 | |
2 5 3`) | |
doScore(input) | |
input = bytes.NewBufferString(`10 | |
7 7 10 1 2 1 7 1 5 9 | |
9 10 6 2 5 6 7 7 5 5 | |
2 7 4 0 7 10 5 6 2 2`) | |
doScore(input) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment