Skip to content

Instantly share code, notes, and snippets.

@morris821028
Created March 11, 2015 02:01
Show Gist options
  • Save morris821028/507e81e686c499fda783 to your computer and use it in GitHub Desktop.
Save morris821028/507e81e686c499fda783 to your computer and use it in GitHub Desktop.
HDE Challenge 003
// You can edit this code!
// Click here and start typing.
// http://hdechallenge.appspot.com/challenge?email=b7615199%40hotmail.com&key=9160760b19bc9fe7dd746d2d53e23e86640f1d71
package main
import "fmt"
func sum(n int) int {
if n == 0 {
return 0
}
var x int
fmt.Scanf("%d", &x)
if x < 0 {
return sum(n - 1)
} else {
return sum(n - 1) + x * x
}
}
func process(testcase int) {
if testcase == 0 {
return
}
var n int
fmt.Scanf("%d", &n)
fmt.Printf("%d\n", sum(n))
process(testcase-1)
}
func main() {
var testcase int
fmt.Scanf("%d", &testcase)
process(testcase)
}
@assman
Copy link

assman commented Mar 14, 2019

Were you selected for the internship

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment