Created
April 26, 2020 20:01
-
-
Save onokonem/98976063d6486eb50d0a717e5ab6a7f0 to your computer and use it in GitHub Desktop.
This file contains 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" | |
"os" | |
"strconv" | |
) | |
func main() { | |
//f, err := os.Create("profile.data") | |
//if err != nil { | |
// panic(err) | |
//} | |
//pprof.StartCPUProfile(f) | |
//defer pprof.StopCPUProfile() | |
mergeArraysA2I(os.Stdin, os.Stdout) | |
} | |
var intMap = make([]int, 101) | |
var arraySep = []byte(" ") | |
func checkWriteError(_ int, err error) { | |
checkError(err) | |
} | |
func checkError(err error) { | |
if err != nil { | |
panic(err) | |
} | |
} | |
func readLine(r *bufio.Reader) []byte { | |
l, _, err := r.ReadLine() | |
if err != nil { | |
panic(err) | |
} | |
return l | |
} | |
func readLineNum(r *bufio.Reader) int { | |
return atoi(string(readLine(r))) | |
} | |
func readLineArrayInt(r *bufio.Reader) []int { | |
l := readLine(r) | |
numbersText := bytes.Split(l, arraySep) | |
numbers := atoi(string(numbersText[0])) | |
res := make([]int, numbers) | |
for i := 1; i < numbers; i++ { | |
res[i] = atoi(string(numbersText[i])) | |
} | |
return res | |
} | |
func atoi(l string) int { | |
n, err := strconv.Atoi(l) | |
if err != nil { | |
panic(err) | |
} | |
return n | |
} | |
func mergeArraysA2I(reader io.Reader, out io.Writer) { | |
r := bufio.NewReaderSize(reader, 102400) | |
w := bufio.NewWriter(out) | |
for arrays := readLineNum(r); arrays > 0; arrays-- { | |
for _, n := range readLineArrayInt(r) { | |
intMap[n]++ | |
} | |
} | |
for i := 0; i <= 100; i++ { | |
iStr := []byte(fmt.Sprintf("%d ", i)) | |
for j := 0; j < intMap[i]; j++ { | |
checkWriteError(w.Write(iStr)) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment