Skip to content

Instantly share code, notes, and snippets.

@narenaryan
Created June 15, 2016 18:38
Show Gist options
  • Select an option

  • Save narenaryan/668d7a1830dbacd874e8c9233c6fdf65 to your computer and use it in GitHub Desktop.

Select an option

Save narenaryan/668d7a1830dbacd874e8c9233c6fdf65 to your computer and use it in GitHub Desktop.
package main
import ("fmt"
"bufio"
"os"
"strconv"
"strings"
)
func cleanString(stream string, seperator string) []int{
// Trims the stream and then splits
trimmed_stream := strings.TrimSpace(stream)
split_arr := strings.Split(trimmed_stream, seperator)
// convert strings to integers and store them in a slice
clean_arr := make([]int, len(split_arr))
for index,val := range split_arr{
clean_arr[index], _ = strconv.Atoi(val)
}
return clean_arr
}
func main() {
inputreader := bufio.NewReader(os.Stdin)
input, _ := inputreader.ReadString('\n')
noOfTestCases, _ := strconv.Atoi(strings.TrimSpace(input))
for i := 0; i < noOfTestCases; i++ {
lineInput, _ := inputreader.ReadString('\n')
fmt.Println(cleanString(lineInput, " "))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment