The error is occurring because input[2] is of type String.Subsequence (also known as Substring), which is a non-optional type. You are trying to force unwrap it using the exclamation mark !, but since it is not an optional, it cannot be force unwrapped.

To fix the error, you can remove the exclamation mark ! from let k = input[2]!:

let k = input[2]

This will assign the value of input[2] to k without force unwrapping it.

import Foundationlet input = readLine!splitseparator let n = Intinput0!let k = input2!var o String = Nofor _ in 0n if let line = readLine linecontainsk o = Yes break printo哪错了:m

原文地址: https://www.cveoy.top/t/topic/iQOJ 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录