Advertisement
Pug_coder

maxnumber

Mar 17th, 2021
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 1.62 KB | None | 0 0
  1. //var 1
  2.  
  3. package main
  4.  
  5. import (
  6.     "fmt"
  7.     "strconv"
  8. )
  9.  
  10. type arrInt []int
  11.  
  12. func partiton(low int, high int, less func(i, j int )bool, swap func(i, j int)) int{
  13.     i := low
  14.     for j := low; j < high; j++ {
  15.         if less(j,high) {
  16.             swap(i,j)
  17.             i++
  18.         }
  19.     }
  20.     swap(i,high)
  21.     return i
  22. }
  23. func quickSortRec(low int, high int, less func(i, j int) bool, swap func(i, j int)){
  24.     if low < high{
  25.         q := partiton(low, high, less ,swap)
  26.         quickSortRec(low , q - 1, less, swap)
  27.         quickSortRec(q + 1, high, less, swap)
  28.     }
  29. }
  30. func qsort(n int, less func(i, j int) bool,swap func(i, j int)) {
  31.     quickSortRec(0, n - 1, less, swap)
  32. }
  33. func main(){
  34.     var n int
  35.     var m int
  36.     fmt.Scan(&n)
  37.     arr := make([]int, n)
  38.     for i:=0; i<n; i++ {
  39.         fmt.Scan(&m)
  40.         arr[i] = m
  41.     }
  42.     qsort(n,
  43.          func(i, j int) bool {
  44.             a := strconv.Itoa(arr[i])
  45.             b := strconv.Itoa(arr[j])
  46.             ch1, _ := strconv.Atoi(a + b)
  47.             ch2, _ := strconv.Atoi(b + a)
  48.             return ch1 > ch2 },
  49.             func(i, j int){arr[i], arr[j] = arr[j], arr[i]})
  50.     for i := 0; i < n; i++{
  51.         fmt.Print(arr[i])
  52.     }
  53. }
  54.  
  55. // var 2
  56.  
  57. package main
  58.  
  59. import (
  60.     "fmt"
  61.     "strconv"
  62.     "sort"
  63. )
  64.  
  65. type arrInt []int
  66. func(arr arrInt) Less(i,j int) bool {
  67.         a := strconv.Itoa(arr[i])
  68.         b := strconv.Itoa(arr[j])
  69.         ch1, _ := strconv.Atoi(a + b)
  70.         ch2, _ := strconv.Atoi(b + a)
  71.         return ch1 > ch2
  72.     }  
  73.  
  74.  
  75. func(arr arrInt) Swap(i,j int) {
  76.  arr[i], arr[j] = arr[j], arr[i]
  77. }
  78. func (arr arrInt) Len() int { return len(arr) }
  79. func main(){
  80.     var n int
  81.     fmt.Scan(&n)
  82.     arr := make([]int, n)
  83.     for i := 0; i < n; i++ {
  84.         fmt.Scan(&arr[i])
  85.     }
  86.     sort.Sort(arrInt(arr))
  87.     for _, e := range arr{
  88.         fmt.Print(e)
  89.     }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement