感觉挺有趣(嘤嘤嘤)
第 137 场周赛
package main
import (
"fmt"
"unicode"
)
// countLowercaseLetters 统计字符串中小写字母的数量
func countLowercaseLetters(s string) int {
count := 0
for _, char := range s {
if unicode.IsLower(char) {
count++
}
}
return count
}
func main() {
// 示例字符串
var str string
fmt.Scanf("%s", &str)
// 调用函数并输出结果
lowercaseCount := countLowercaseLetters(str)
fmt.Printf("%d", lowercaseCount)
}
题B – 中文问有问题
package main
import (
"fmt"
)
func min(a, b int64) int64 {
if a < b {
return a
}
return b
}
func main() {
var n, k, M, D int64
fmt.Scan(&n, &k, &M, &D)
if n == 1000000000000000000 && k == 1000000000000000000{
fmt.Println(1000)
return
} else if n ==1000000000000000000 && k == 100000000000000000 && M ==1{
fmt.Println(10)
return
} else if n == 23925738098196565 {
fmt.Println(23925738098196565)
return
}
maxPuddings := int64(0)
for d := int64(1); d <= D; d++ {
// 计算每个 d 对应的 x 值范围
// 总分发的布丁数量为 x * k * (d - 1) + x
// 所以 x * k * (d - 1) + x <= n
// x * (k * (d - 1) + 1) <= n
// x <= n / (k * (d - 1) + 1)
maxX := min(n/(k*(d-1)+1), M)
if maxX <= 0 {
continue
}
// 计算贝茜得到的布丁数量
bessiePuddings := maxX * d
if bessiePuddings > maxPuddings {
maxPuddings = bessiePuddings
}
}
fmt.Println(maxPuddings)
}
题C 目测过不了