We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
packagemainimport("fmt""math")funcmain(){vartextstringfmt.Scan(&text)l:=len(text)m:=math.Sqrt(float64(l))lower:=int(math.Floor(m))upper:=int(math.Ceil(m))// upper * upper must be >= l, so it safe to do following. Or just simply do one lower += 1forlower*upper<l{lower+=1}index:=0fori:=0;i<upper;i++{forj:=0;j<lower;j++{index=i+j*upperifindex>=l{break}fmt.Printf("%c",text[index])}fmt.Printf(" ")}}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Encryption
You are viewing a single comment's thread. Return to all comments →
Don't need to use a 2d array.