→ Litfal: 沒寫題目是要擲盃喔... 05/01 12:08
原本只是認為我單純詢問為何這段CODE會產生這個問題,所以沒打算貼題目出來
只不過依您要求
題目: #824 Goat Latin 難度:easy
A sentence S is given, composed of words separated by spaces. Each word
consists of lowercase and uppercase letters only.
We would like to convert the sentence to "Goat Latin" (a made-up language
similar to Pig Latin.)
The rules of Goat Latin are as follows:
If a word begins with a vowel (a, e, i, o, or u), append "ma" to the end
of the word.
For example, the word 'apple' becomes 'applema'.
If a word begins with a consonant (i.e. not a vowel), remove the first
letter and append it to the end, then add "ma".
For example, the word "goat" becomes "oatgma".
Add one letter 'a' to the end of each word per its word index in the
sentence, starting with 1.
For example, the first word gets "a" added to the end, the second word
gets "aa" added to the end and so on.
Return the final sentence representing the conversion from S to Goat Latin.
簡單來說:
1. Input string , return string
2. If words' first char is a,e,i,o,u ,then append "ma" after the word
3. If words' first char isnt a,e,i,o,u , then the first char put
the words end.
4. increase 'a' per word and put it to the end word .
→ t64141: System.Collections.Generic.List`1[System.Char]這是你 05/01 13:13
→ t64141: 把整個list丟進Console.WriteLine()印出來的吧? 05/01 13:14
→ t64141: ex: Console.WriteLine(list), list是一個List<Char>物件 05/01 13:15
先感謝您的回覆,這題目前已經用別的寫法解出來了 只不過還是好奇錯在哪
我跟你的想法一樣,他直接把我 list這個 object 給印出來
但我用 List.ToString()、 Array.ToString() 應該是直接把List內的value
給變成ToString() 才對呀@@
為何會變成單純show list 而已??
※ 編輯: ken52011219 (101.13.112.92), 05/01/2018 13:31:21
→ t64141: 如果是的話,可能就是Console.Write()的參數放錯 05/01 13:17
※ 編輯: ken52011219 (101.13.112.92), 05/01/2018 13:37:21
→ t64141: List<>好像沒有實作ToString(),所以你的情境他做的是 05/01 13:40
→ t64141: Object.ToString() 05/01 13:40
→ t64141: object.ToString()是回傳GetType().ToString(); 做的是 05/01 13:42
→ t64141: Type.ToString() 05/01 13:43
→ t64141: Type.ToString()找一下MSDN可以發現就是印出型別 05/01 13:45
→ t64141: 平時也沒記這麼細節的地方,剛剛臨時去查的,看看就好 05/01 13:46
→ t64141: 123.ToString()能正確轉成字串是因為Int32.ToString()覆寫 05/01 13:49
→ t64141: 了Object.ToString(),所以才能直覺的數字轉字串...吧 05/01 13:50
剛剛稍微在網路搜尋印證了t大的說法
List.ToString() 是 Object.ToString() 沒錯 ,非常感謝解惑<(_ _)>
※ 編輯: ken52011219 (101.13.112.92), 05/01/2018 13:59:06