You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Oct 21, 2019. It is now read-only.
package main
import "fmt"
func main() {
var tesNum int
_, err := fmt.Scanln(&tesNum)
if err != nil {
}
var vKey = 0
for i := 0; i < tesNum; i++ {
_, err := fmt.Scanln(&vKey)
if err != nil {
}
var vValue = make([]int, vKey)
var max = [2] int{0, 0}
for j := 0; j < vKey; j++ {
_, err = fmt.Scan(&vValue[j])
if err != nil {
}
if vValue[j] > max[0] {
max[1] = max[0]
max[0] = vValue[j]
continue
}
if vValue[j] > max[1] {
max[1] = vValue[j]
}
}
v1 := max[1] - 1
v2 := vKey - 2
if v1 <= v2 {
fmt.Println(v1)
} else {
fmt.Println(v2)
}
}
}
然后!第一个 case 就挂!!最后经 @BLF2 同学指导,发现是输入可能以空格结束,用 Scan 可以,用 Scanln 就不行。(╯‵□′)╯︵┻━┻
后来用 Py 过的:
if __name__ == "__main__":
test_num = int(input())
while test_num:
test_num -= 1
arr_num = int(input())
arr = input()
num = [int(n) for n in arr.split()]
num = sorted(num)
result = min(num[-2] - 1, arr_num - 2)
print(result)
总结:
不用 Scanln 获取输入!!!
The text was updated successfully, but these errors were encountered:
昨天死在 A 题上了_(:з」∠)_
A 题
题意:给你 n 个木棍 ,求出可以组成楼梯的最大台阶数。
根据题意可列出方程:
即求得 max2 - 1 和 n - 2 取最小就好了。
然后!第一个 case 就挂!!最后经 @BLF2 同学指导,发现是输入可能以空格结束,用 Scan 可以,用 Scanln 就不行。(╯‵□′)╯︵┻━┻
后来用 Py 过的:
总结:
不用 Scanln 获取输入!!!
The text was updated successfully, but these errors were encountered: