1 Star 4 Fork 1

张磊/cangjie_practice

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
read_until_demo.cj 1014 Bytes
一键复制 编辑 原始数据 按行查看 历史
张磊 提交于 2025-07-13 16:27 +08:00 . 适配仓颉语言1.0.0正式版本
import std.console.*
var lastChr = Option<Rune>.None
func untilDouble9(newChr: Rune): Bool {
//如果上一个字符存在
if (let Some(last) <- lastChr) {
//如果上一个字符和现在的字符都是9
if (last == r'9' && newChr == r'9') {
return true
} else {
lastChr = newChr
return false
}
} else {
lastChr = newChr
}
return false
}
main() {
println("Input string, including two consecutive Runeacters 9:")
try {
//读取字符串,如果读取的内容包括两个连续的9,就返回截止到这两个9的子字符串
var input = Console.stdIn.readUntil(untilDouble9)
//判断结果是不是None,是就继续循环
while (let None <- input) {
//重新读取
input = Console.stdIn.readUntil(untilDouble9)
}
println(input.getOrThrow())
} catch (e: Exception) {
println("An error occurred:" + e.message)
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zl3624/cangjie_practice.git
git@gitee.com:zl3624/cangjie_practice.git
zl3624
cangjie_practice
cangjie_practice
master

搜索帮助