C_Sharp 板


LINE

public class Solution { public string ToGoatLatin(string S) { String [] words = S.Split(' '); List<char> vowel = new List<char>() { 'a','e','i','o','u','A','E','I','O','U' }; StringBuilder ans = new StringBuilder(); StringBuilder a = new StringBuilder(); foreach(string s in words) //s 正常 { List<char> change_word = s.ToList(); if (vowel.IndexOf(change_word[0])==-1) { change_word.Insert(change_word.Count,change_word[0]); change_word.RemoveAt(0); } a.Append("a"); ans.Append(" " + change_word.ToString() + "ma" + a); } return ans.Remove(ans.Length," " ).ToString() ; } } 目前COMPLIER 是過的,但怎麼修改答案都是 " System.Collections.Generic.List`1[System.Char]maa System.Collections.Generic.List`1[System.Char]maaa System.Collections.Generic.List`1[System.Char]maaaa System.Collections.Generic.List`1[System.Char]maaaaa" 但若以input "I speak Goat Latin" 為例,應該是要為 「 Imaa peaksmaaa oatGmaaaa atinLmaaaa」 第一次在板上發文,請各位大大解惑 感謝<(__ )> --   有一個香錦囊,是從一個神話般的守軍的血屍頂上剝下的。那一次我們部隊遭受從未 有過的頑強抵抗,我們犧牲了三個艦隊,一個裝甲師和無以數計小組推進的敢死排,才摧 毀了那處隘口的碉堡。但是竟然發現,使我們遭受如此慘烈傷亡的守軍,總數只有一人。   士兵們起鬨地在他胸前發現這枚香袋,大家都相信這是一枚具有神奇力量的護身符。 我們把他的頭顱砍斷,取下香袋,剝開,   裡面一張被血浸紅的宣紙竟用漢字娟娟秀秀四個整齊的楷書寫著-「盼君早歸。」 --



※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 101.13.112.92
※ 文章網址: https://webptt.com/m.aspx?n=bbs/C_Sharp/M.1525139205.A.F85.html
1F:→ 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 .
2F:→ t64141: System.Collections.Generic.List`1[System.Char]這是你 05/01 13:13
3F:→ t64141: 把整個list丟進Console.WriteLine()印出來的吧? 05/01 13:14
4F:→ 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
5F:→ t64141: 如果是的話,可能就是Console.Write()的參數放錯 05/01 13:17
※ 編輯: ken52011219 (101.13.112.92), 05/01/2018 13:37:21
6F:→ t64141: List<>好像沒有實作ToString(),所以你的情境他做的是 05/01 13:40
7F:→ t64141: Object.ToString() 05/01 13:40
8F:→ t64141: 根據https://referencesource.microsoft.com/ 05/01 13:41
9F:→ t64141: object.ToString()是回傳GetType().ToString(); 做的是 05/01 13:42
10F:→ t64141: Type.ToString() 05/01 13:43
11F:→ t64141: Type.ToString()找一下MSDN可以發現就是印出型別 05/01 13:45
12F:→ t64141: 平時也沒記這麼細節的地方,剛剛臨時去查的,看看就好 05/01 13:46
13F:→ t64141: 123.ToString()能正確轉成字串是因為Int32.ToString()覆寫 05/01 13:49
14F:→ t64141: 了Object.ToString(),所以才能直覺的數字轉字串...吧 05/01 13:50
剛剛稍微在網路搜尋印證了t大的說法 List.ToString() 是 Object.ToString() 沒錯 ,非常感謝解惑<(_ _)> ※ 編輯: ken52011219 (101.13.112.92), 05/01/2018 13:59:06







like.gif 您可能會有興趣的文章
icon.png[問題/行為] 貓晚上進房間會不會有憋尿問題
icon.pngRe: [閒聊] 選了錯誤的女孩成為魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一張
icon.png[心得] EMS高領長版毛衣.墨小樓MC1002
icon.png[分享] 丹龍隔熱紙GE55+33+22
icon.png[問題] 清洗洗衣機
icon.png[尋物] 窗台下的空間
icon.png[閒聊] 双極の女神1 木魔爵
icon.png[售車] 新竹 1997 march 1297cc 白色 四門
icon.png[討論] 能從照片感受到攝影者心情嗎
icon.png[狂賀] 賀賀賀賀 賀!島村卯月!總選舉NO.1
icon.png[難過] 羨慕白皮膚的女生
icon.png閱讀文章
icon.png[黑特]
icon.png[問題] SBK S1安裝於安全帽位置
icon.png[分享] 舊woo100絕版開箱!!
icon.pngRe: [無言] 關於小包衛生紙
icon.png[開箱] E5-2683V3 RX480Strix 快睿C1 簡單測試
icon.png[心得] 蒼の海賊龍 地獄 執行者16PT
icon.png[售車] 1999年Virage iO 1.8EXi
icon.png[心得] 挑戰33 LV10 獅子座pt solo
icon.png[閒聊] 手把手教你不被桶之新手主購教學
icon.png[分享] Civic Type R 量產版官方照無預警流出
icon.png[售車] Golf 4 2.0 銀色 自排
icon.png[出售] Graco提籃汽座(有底座)2000元誠可議
icon.png[問題] 請問補牙材質掉了還能再補嗎?(台中半年內
icon.png[問題] 44th 單曲 生寫竟然都給重複的啊啊!
icon.png[心得] 華南紅卡/icash 核卡
icon.png[問題] 拔牙矯正這樣正常嗎
icon.png[贈送] 老莫高業 初業 102年版
icon.png[情報] 三大行動支付 本季掀戰火
icon.png[寶寶] 博客來Amos水蠟筆5/1特價五折
icon.pngRe: [心得] 新鮮人一些面試分享
icon.png[心得] 蒼の海賊龍 地獄 麒麟25PT
icon.pngRe: [閒聊] (君の名は。雷慎入) 君名二創漫畫翻譯
icon.pngRe: [閒聊] OGN中場影片:失蹤人口局 (英文字幕)
icon.png[問題] 台灣大哥大4G訊號差
icon.png[出售] [全國]全新千尋侘草LED燈, 水草

請輸入看板名稱,例如:e-shopping站內搜尋

TOP