朋友留的电话里夹着横线、空格和括号。写 count_digits(phone),只数 '0' 到 '9' 的字符有几个,别的都不算。空字符串返回 0。
count_digits("138-0013-8000")→11count_digits("")→0int count_digits(const char *phone)int count_digits(const char *phone) {
int n = 0;
for (int i = 0; phone[i] != '\0'; i++) {
// 在这里写:是 '0' 到 '9' 之间的字符,n 就加 1
}
return n;
}
写好了先点「运行」试试示例,没问题再点「提交」。