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/cn.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灯, 水草

请输入看板名称,例如:BabyMother站内搜寻

TOP