こんにちは、ナナオです。
前回に引き続き競プロを実施していきたいと思います。
今回の問題は以下です。
実装
以下のように実装しました。
package main
import (
"fmt"
"unicode"
)
func main() {
var s string
fmt.Scan(&s)
if len(s) < 6 || len(s) > 64 {
fmt.Println("invalid")
return
}
upper := false
lower := false
number := false
symbol := false
for _, r := range s {
switch {
case !upper && unicode.IsUpper(r): upper = true
case !lower && unicode.IsLower(r): lower = true
case !number && unicode.IsNumber(r): number = true
case !symbol && (unicode.IsSymbol(r) || unicode.IsPunct(r)): symbol = true
}
}
cond := []bool{
len(s) >= 10,
upper,
lower,
number,
symbol,
}
score := 0
for _, ok := range cond {
if ok {
score++
}
}
if score <= 2 {
fmt.Println("weak")
} else if score == 3 {
fmt.Println("medium")
} else if score >= 4 {
fmt.Println("strong")
}
}
ちょっと工夫したところとしては、upperとかの条件を一つのスライスに入れて判定してるところですかね。
ということで今回はこれで👍