You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This program gets input from stdin.
The first input indicates how many groups of numbers.
The second input is also a number, which means how many numbers in the first group.
The third input can be a string of numbers, separated by space. These are all the numbers in the first group.
By repeating the second and third steps, we can input multi-groups of numbers.
The output is the square sums (all the negative numbers are ignored) of the numbers in each group.
e.g.
inputs:
2 //2 Groups
2 //2 Numbers in the first group
1 2 //First group
1 //1 Number in the second group
4// Second Group
outputs:
5 //11+22
16//4*4
Issue:
Here is the intended result from GoLand:
inputs:
2
1
-1
1
1
outputs:
0
1
But from the CMD terminal:
C:\Users\Vic\Desktop\challenge>go run c.go
2
1
-1
panic: runtime error: index out of range
Your readLine function buffers an unspecified quantity of input from os.Stdin, then returns the first line of that input — discarding the remainder. It most likely displays different results in the two environments due to a different pattern of writes to stdin.
Environment: Go version: go1.12.9 windows/amd64, Windows 10 1903, GoLand Version: 2019.2
Code File:
c.txt
This program gets input from stdin.
The first input indicates how many groups of numbers.
The second input is also a number, which means how many numbers in the first group.
The third input can be a string of numbers, separated by space. These are all the numbers in the first group.
By repeating the second and third steps, we can input multi-groups of numbers.
The output is the square sums (all the negative numbers are ignored) of the numbers in each group.
e.g.
inputs:
2 //2 Groups
2 //2 Numbers in the first group
1 2 //First group
1 //1 Number in the second group
4// Second Group
outputs:
5 //11+22
16//4*4
Issue:
Here is the intended result from GoLand:
inputs:
2
1
-1
1
1
outputs:
0
1
But from the CMD terminal:
C:\Users\Vic\Desktop\challenge>go run c.go
2
1
-1
panic: runtime error: index out of range
goroutine 1 [running]:
main.IterElements(0xfffffffffffffffe, 0xc0000402b0, 0x0, 0x0, 0xc00005c420)
C:/Users/Vic/Desktop/challenge/c.go:22 +0x13a
main.IterElements(0xffffffffffffffff, 0xc0000402b0, 0x1, 0x1, 0x0)
C:/Users/Vic/Desktop/challenge/c.go:33 +0x105
main.iterGroups(0x1)
C:/Users/Vic/Desktop/challenge/c.go:45 +0x11e
main.iterGroups(0x2)
C:/Users/Vic/Desktop/challenge/c.go:49 +0x163
main.main()
C:/Users/Vic/Desktop/challenge/c.go:67 +0xba
exit status 2
Not sure what is wrong here, any help?
Thank you!
The text was updated successfully, but these errors were encountered: