SHARE
TWEET

Untitled

a guest Mar 24th, 2019 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package main
  2.  
  3. import (
  4.     "fmt"
  5. )
  6.  
  7. func calculate(X int) int {
  8.     if X==0{
  9.       //if X == 0 stop calculate
  10.       return 0
  11.     }
  12.  
  13.     //get the integer
  14.     var integers int
  15.     fmt.Scan(&integers)
  16.  
  17.  
  18.     //calcualte sum of square if integer >= 0
  19.     if (integers >= 0){
  20.       return integers*integers + calculate(X-1)
  21.     } else {
  22.       return calculate(X-1)
  23.     }
  24.    
  25.    
  26. }
  27.  
  28.  
  29. func testCase(N int) {
  30.     if N == 0 {
  31.       //if N == 0 stop test case
  32.         return
  33.     }
  34.  
  35.   //get how many integers
  36.   var X int
  37.   fmt.Scan(&X)
  38.  
  39.   //print and calculate sum of squares
  40.   fmt.Println(calculate(X))
  41.  
  42.   //run next test case
  43.     testCase(N-1)
  44. }
  45.  
  46. func main() {
  47.   //get N from stdin
  48.   var N int
  49.   fmt.Scan(&N)
  50.   //Run test case for N times
  51.     testCase(N)
  52. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top