package main
import (
"fmt"
)
type Kamus struct {
data map[string]map[string]bool
}
// Constructor untuk membuat instance baru dari Kamus
func NewKamus() *Kamus {
return &Kamus{
data: make(map[string]map[string]bool),
}
}
// Menambahkan kata dan sinonimnya ke dalam kamus
func (k *Kamus) Tambah(kata string, sinonim []string) {
if k.data[kata] == nil {
k.data[kata] = make(map[string]bool)
}
for _, s := range sinonim {
k.data[kata][s] = true
if k.data[s] == nil {
k.data[s] = make(map[string]bool)
}
k.data[s][kata] = true
}
}
// Mengambil semua sinonim dari sebuah kata
func (k *Kamus) AmbilSinonim(kata string) []string {
sinonimSet, exists := k.data[kata]
if !exists {
return nil
}
result := make([]string, 0)
for sinonim := range sinonimSet {
result = append(result, sinonim)
}
return result
}
func main() {
kamus := NewKamus()
kamus.Tambah("big", []string{"large", "great"})
kamus.Tambah("big", []string{"huge", "fat"})
kamus.Tambah("huge", []string{"enormous", "gigantic"})
fmt.Println("Sinonim dari 'big':", kamus.AmbilSinonim("big"))
fmt.Println("Sinonim dari 'huge':", kamus.AmbilSinonim("huge"))
fmt.Println("Sinonim dari 'gigantic':", kamus.AmbilSinonim("gigantic"))
fmt.Println("Sinonim dari 'colossal':", kamus.AmbilSinonim("colossal"))
}
cGFja2FnZSBtYWluCgppbXBvcnQgKAoJImZtdCIKKQoKdHlwZSBLYW11cyBzdHJ1Y3QgewoJZGF0YSBtYXBbc3RyaW5nXW1hcFtzdHJpbmddYm9vbAp9CgovLyBDb25zdHJ1Y3RvciB1bnR1ayBtZW1idWF0IGluc3RhbmNlIGJhcnUgZGFyaSBLYW11cwpmdW5jIE5ld0thbXVzKCkgKkthbXVzIHsKCXJldHVybiAmS2FtdXN7CgkJZGF0YTogbWFrZShtYXBbc3RyaW5nXW1hcFtzdHJpbmddYm9vbCksCgl9Cn0KCi8vIE1lbmFtYmFoa2FuIGthdGEgZGFuIHNpbm9uaW1ueWEga2UgZGFsYW0ga2FtdXMKZnVuYyAoayAqS2FtdXMpIFRhbWJhaChrYXRhIHN0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