Last active
May 27, 2018 23:00
-
-
Save dryleaf/d9f6b8c1e23a483387410aa2b599eb1b to your computer and use it in GitHub Desktop.
HDE programming challenge
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 ( | |
"fmt" | |
"bytes" | |
"strconv" | |
) | |
func main() { | |
var N int | |
fmt.Scanln(&N) | |
readCases(N) | |
fmt.Print(buffer.String()) | |
} | |
var buffer bytes.Buffer | |
func readCases(N int) { | |
if N == 0 { | |
return | |
} | |
var X int | |
fmt.Scanln(&X) | |
buffer.WriteString(strconv.Itoa(readXs(X))+"\n") | |
readCases(N - 1) | |
} | |
func readXs(x int) int { | |
if x == 0 { | |
return 0 | |
} | |
var y int | |
fmt.Scanf("%d", &y) | |
if y >= 0 { | |
return y * y + readXs(x - 1) | |
} else { | |
return readXs(x - 1) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment