Advertisement
Guest User

For den

a guest
Nov 15th, 2019
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.74 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.     "fmt"
  5.     "strconv"
  6. )
  7.  
  8. func main() {
  9.     //var num int64
  10.     //fmt.Println(getSpreadsheetNotation(num))
  11.     fmt.Println(getSpreadsheetNotation(27))
  12.     fmt.Println(getSpreadsheetNotation(1405))
  13. }
  14.  
  15. func getSpreadsheetNotation(a int64) string {
  16.  
  17.     var div702 int64 = a / 702
  18.     var mod702 int64 = a % 702
  19.  
  20.     if mod702 != 0 {
  21.         div702++
  22.     } else {
  23.         mod702 = 702
  24.     }
  25.  
  26.     var div26 int64 = mod702 / 26
  27.     var mod26 int64 = mod702 % 26
  28.  
  29.     if mod26 == 0 {
  30.         mod26 = 26
  31.         div26--
  32.     }
  33.  
  34.     var firstLetter = string('A' - 1 + div26)
  35.     var secondLetter = string('A' - 1 + mod26)
  36.  
  37.     if div26 == 0 {
  38.         return strconv.FormatInt(div702, 10) + secondLetter
  39.     } else {
  40.         return strconv.FormatInt(div702, 10) + firstLetter + secondLetter
  41.     }
  42.  
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement