R solving hackerrank challenge

后端 未结 5 836
挽巷
挽巷 2020-12-31 18:55

I would like to solve the challenge. The language of my preference is R. I am not sure how to receive input. On hackerrank coding window it says that

\"# En         


        
5条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2020-12-31 19:19

    Another approach:

    con = file('stdin', open ='r')
    input  = readLines(con)
    z = c()
    for(i in 2:length(input)){
      z = c(z, as.numeric(input[[i]]))
    }
    
    cat(format(round(sum(z)/2, 1), nsmall = 1), sep = "\n")
    

提交回复
热议问题