mirror of https://github.com/01-edu/public.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
651 B
47 lines
651 B
5 years ago
|
package main
|
||
5 years ago
|
|
||
|
import (
|
||
5 years ago
|
"fmt"
|
||
5 years ago
|
"sort"
|
||
5 years ago
|
|
||
|
"./student"
|
||
5 years ago
|
)
|
||
|
|
||
|
func intToDigits(n int) (digits []int) {
|
||
|
for n > 0 {
|
||
|
if n == 0 {
|
||
|
digits = append(digits, 0)
|
||
|
} else {
|
||
|
digits = append(digits, n%10)
|
||
|
}
|
||
|
n /= 10
|
||
|
}
|
||
|
return
|
||
|
}
|
||
|
|
||
5 years ago
|
func printNbrInOrder(n int) {
|
||
5 years ago
|
if n == 0 {
|
||
5 years ago
|
fmt.Print("0")
|
||
5 years ago
|
return
|
||
|
}
|
||
5 years ago
|
digits := intToDigits(n)
|
||
|
sort.Ints(digits)
|
||
|
for _, i := range digits {
|
||
5 years ago
|
fmt.Printf("%c", rune(i)+'0')
|
||
5 years ago
|
}
|
||
5 years ago
|
fmt.Println()
|
||
5 years ago
|
}
|
||
5 years ago
|
|
||
|
func main() {
|
||
|
table := append(
|
||
|
lib.MultRandIntBetween(0, lib.MaxInt),
|
||
|
lib.MaxInt,
|
||
|
321,
|
||
|
321321,
|
||
|
0,
|
||
|
)
|
||
|
for _, arg := range table {
|
||
|
lib.Challenge("PrintNbrInOrder", student.PrintNbrInOrder, printNbrInOrder, arg)
|
||
|
}
|
||
|
}
|