|
|
import Foundation
|
|
|
|
|
|
// 把 task 4 得成果贴过来,在 task 4 的基础上继续往下写
|
|
|
|
|
|
// 以下的内容将能够判断名为 ID 的字符串是否满足13位数字,以20xx开头,第5位为1-3的情况,可以直接照搬
|
|
|
// let reFormula = try! NSRegularExpression(pattern: "^20\\d{2}[1-3]\\d{8}$", options: [NSRegularExpression.Options.anchorsMatchLines])
|
|
|
// let matchRange = NSRange(ID.startIndex..<ID.endIndex, in: ID)
|
|
|
// let matchList = reFormula.matches(in: ID, range: matchRange)
|
|
|
// if matchList.count != 1 {
|
|
|
// return nil
|
|
|
// }
|
|
|
|
|
|
// 以下的内容将能够判断名为 ID 的字符串是否满足13位数字的情况,可以直接照搬
|
|
|
// let reFormula = try! NSRegularExpression(pattern: "^\\d{13}$", options: [NSRegularExpression.Options.anchorsMatchLines])
|
|
|
// let matchRange = NSRange(ID.startIndex..<ID.endIndex, in: ID)
|
|
|
// let matchList = reFormula.matches(in: ID, range: matchRange)
|
|
|
// if matchList.count != 1 {
|
|
|
// return nil
|
|
|
// }
|
|
|
|
|
|
// 以下的内容将能够判断名为 ID 的字符串是否满足13位数字,开头为0000的情况,可以直接照搬
|
|
|
// let reFormula = try! NSRegularExpression(pattern: "^0000\\d{9}$", options: [NSRegularExpression.Options.anchorsMatchLines])
|
|
|
// let matchRange = NSRange(ID.startIndex..<ID.endIndex, in: ID)
|
|
|
// let matchList = reFormula.matches(in: ID, range: matchRange)
|
|
|
// if matchList.count != 1 {
|
|
|
// return nil
|
|
|
// }
|
|
|
|
|
|
// 测试用,不需要更改
|
|
|
var siuziu = Student(id: "2022202121000", name: "小趙")
|
|
|
var siuchow = Student(id: "2000503205613", name: "小周")
|
|
|
var studentList = [siuziu, siuchow]
|
|
|
|
|
|
for item in studentList {
|
|
|
guard item != nil else {
|
|
|
print("Invalid students")
|
|
|
continue
|
|
|
}
|
|
|
do {
|
|
|
var count = 0
|
|
|
while true{
|
|
|
count += 1
|
|
|
try item!.work()
|
|
|
print("Siu Ziu has worked for \(String(count)) \(count <= 1 ? "hour" : "hours").")
|
|
|
}
|
|
|
}
|
|
|
catch InsufficientEnergy.crazyThursdayVMe50 {
|
|
|
print("I'm hungry, please v me 50!")
|
|
|
}
|
|
|
}
|
|
|
|