The C Programming Language Exercise 3-3
題目:
Write a function expand(s1,s2) that expands shorthand notations like a-z in the string s1 into the equivalent complete list abc...xyz in s2 . Allow for letters of either case and digits, and be prepared to handle cases like a-b-c and a-z0-9 and -a-z . Arrange that a leading or trailing - is taken literally.
解法:
覺得還滿有趣的一題。判斷「-」是否為字串的第一或最後一個字元,再處理字母與數字問題即可。
A-A類的也要稍微判斷。
沒有留言:
張貼留言