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.
57 lines
1.1 KiB
57 lines
1.1 KiB
5 years ago
|
package main
|
||
|
|
||
5 years ago
|
import "./student"
|
||
|
|
||
|
func isAnagram(s, t string) bool {
|
||
|
alph := make([]int, 26)
|
||
|
for i := 0; i < len(s); i++ {
|
||
|
if s[i] < 'a' || s[i] > 'z' {
|
||
|
continue
|
||
|
}
|
||
|
alph[s[i]-'a']++
|
||
|
}
|
||
|
for i := 0; i < len(t); i++ {
|
||
|
if t[i] < 'a' || t[i] > 'z' {
|
||
|
continue
|
||
|
}
|
||
|
alph[t[i]-'a']--
|
||
|
}
|
||
|
for i := 0; i < 26; i++ {
|
||
|
if alph[i] != 0 {
|
||
|
return false
|
||
|
}
|
||
|
}
|
||
|
return true
|
||
|
}
|
||
5 years ago
|
|
||
5 years ago
|
func main() {
|
||
5 years ago
|
table := [][2]string{
|
||
|
{"listen", "silent"},
|
||
|
{"alem", "school"},
|
||
|
{"neat", "a net"},
|
||
|
{"anna madrigal", "a man and a girl"},
|
||
|
{"abcc", "abcd"},
|
||
|
{"aaaac", "caaaa"},
|
||
|
{"", ""},
|
||
|
{" ", ""},
|
||
|
{"lyam", "meow"},
|
||
|
{"golang", "lang go"},
|
||
|
{"verylongword", "v e r y l o n g w o r d"},
|
||
|
{"chess", "ches"},
|
||
|
{"anagram", "nnagram"},
|
||
|
{"chess", "board"},
|
||
|
{"mmm", "m"},
|
||
|
{"pulp", "fiction"},
|
||
5 years ago
|
}
|
||
|
for i := 0; i < 15; i++ {
|
||
5 years ago
|
table = append(table, [2]string{
|
||
5 years ago
|
lib.RandStr(lib.RandIntBetween(15, 20), "qwertyuiopasdfghjklzxcvbnm "),
|
||
|
lib.RandStr(lib.RandIntBetween(15, 20), "qwertyuiopasdfghjklzxcvbnm "),
|
||
5 years ago
|
})
|
||
5 years ago
|
}
|
||
|
|
||
5 years ago
|
for _, arg := range table {
|
||
5 years ago
|
lib.Challenge("IsAnagram", student.IsAnagram, isAnagram, arg[0], arg[1])
|
||
5 years ago
|
}
|
||
5 years ago
|
}
|