Open vkorbes opened 4 years ago
https://play.golang.org/p/WrsSododUgM
package main
/* - Partindo do código abaixo, ordene a []int e a []string.
- https://play.golang.org/p/H_q75mpmHW */
import (
"fmt"
"sort"
)
func main() {
xi := []int{5, 8, 2, 43, 17, 987, 14, 12, 21, 1, 4, 2, 3, 93, 13}
xs := []string{"random", "rainbow", "delights", "in", "torpedo", "summers", "under", "gallantry", "fragmented", "moons", "across", "magenta"}
fmt.Println(xi)
// sort xi
sort.Ints(xi)
fmt.Println(xi)
fmt.Println(xs)
// sort xs
sort.Strings(xs)
fmt.Println(xs)
}
Output
[5 8 2 43 17 987 14 12 21 1 4 2 3 93 13]
[1 2 2 3 4 5 8 12 13 14 17 21 43 93 987]
[random rainbow delights in torpedo summers under gallantry fragmented moons across magenta]
[across delights fragmented gallantry in magenta moons rainbow random summers torpedo under]
Program exited.
My solution:
package main
import (
"fmt"
"sort"
)
func main() {
xi := []int{5, 8, 2, 43, 17, 987, 14, 12, 21, 1, 4, 2, 3, 93, 13}
xs := []string{"random", "rainbow", "delights", "in", "torpedo", "summers", "under", "gallantry", "fragmented", "moons", "across", "magenta"}
fmt.Println(xi)
// sort xi
sort.Ints(xi)
fmt.Println(xi)
fmt.Println(xs)
// sort xs
sort.Strings(xs)
fmt.Println(xs)
}
Cap. 17 – Exercícios: Nível #8 – 4 https://go.dev/play/p/I1pY8TlIpzp
https://go.dev/play/p/M8FDdKE-t6l
package main
import (
"fmt"
"sort"
)
func main() {
xi := []int{5, 8, 2, 43, 17, 987, 14, 12, 21, 1, 4, 2, 3, 93, 13}
xs := []string{"random", "rainbow", "delights", "in", "torpedo", "summers", "under", "gallantry", "fragmented", "moons", "across", "magenta"}
fmt.Println(xi)
// sort xi
sort.Ints(xi)
fmt.Println(xi)
fmt.Println(xs)
// sort xs
sort.Strings(xs)
fmt.Println(xs)
}
Exercício: Capítulo 17, Exercício 4 (Nível: 8)
Use esta thread para compartilhar sua solução, discutir o exercício com os colegas e pedir ajuda caso tenha dificuldades!