明信片的格子很小,先看看最長的詞有多長。寫 longest_word(s),返回 s 裡最長那個詞有幾個字母。詞之間是空格(可能不止一個);空字串返回 0。
longest_word("see you at the beach")→5longest_word("")→0int longest_word(const char *s)int longest_word(const char *s) {
int now = 0;
int best = 0;
for (int i = 0; s[i] != '\0'; i++) {
// 在這裡寫:遇到空格 now 歸零;不然 now 加 1,比 best 大就記下來
}
return best;
}
寫好了先點「執行」試試示例,沒問題再點「提交」。