Problem with Go online judge configurations?

Hello @ all and in particular to the admins,

This question has been bugging me for a while, and a previous post I made might have been unclear… So, now, I’ll use a concrete example to ask my question once again…

I have recently started learning the Go programming language (read more [here][1] ) and I decided that a great place to develop my skills at it would be using the Codechef problems :smiley:

However, I have reasons to believe that the judge might still have bugs… I have been getting some very strange Runtime errors on almost all problems I’ve attempted to solve on the easy practice section… And now I decided to test my theory by solving the easiest possible problem from the Peer section:

This was my accepted C++ solution:

#include <stdio.h>
 
int main()
{
int N;
scanf("%d", &N);
for(int a = 0; a < N; a++)
{
int elem;
scanf("%d", &elem);
if(elem >= 0)
printf("%d \n", elem);
else
printf("%d \n", elem*(-1));
}
return 0;
}

And this is my direct Go translation of it:

package main

import "fmt"

func main(){
var N int
var x int
fmt.Scanf("%d", &N)
for i := 0; i < N; i+=1{
fmt.Scanf("%d", &x)
if x >= 0{
fmt.Println(x)
}else{
fmt.Println(x*(-1))
}
}
}

If anyone could explain me how to get Accepted in Go, I would be very, very grateful!!

Thank you in advance,

Bruno
[1]: http://golang.org

1 Like

My story is very similar to your. I’m learning golang too.
My solution for this problem is very close to your. There are two differences. I use fmt.Scan method to obtain data. And -x expression to inverse sign. It was accepted.

1 Like
//