【小菜日志】用C#完成Allen Lee's Magic大虾推荐的F#作业&F#学习中

人Ren都是达西,F#学习中,希望可以早日写出自己的F#版本,做个记号 

推荐地址:http://www.cnblogs.com/allenlooplee/archive/2009/03/26/1421960.html

原文地址:http://blogs.msdn.com/jomo_fisher/archive/2007/11/17/tight-code-a-puzzle-in-f.aspx

        public static void Main(string[] args)
        {
            
//现在的我 = [['a';'b';'1'];['c';'d';'2'];['e';'f';'3']] 
            
//想要变成 = [['a';'c';'e'];['b';'d';'f'];['1';'2';'3']] 
            string[,] list = { { "a""b""1" }, { "c""d""2" }, { "e""f""3" } };

            StringBuilder sb 
= new StringBuilder();
            sb.Append(
"{");
            
for (int i = 0; i < list.GetLength(0); i++)
            {
                sb.Append(
"{");
                
for (int j = 0; j < list.GetLength(1); j++)
                {
                    sb.Append(
"\"" + list[j, i] + "\",");
                }
                sb.Remove(sb.ToString().Length 
- 11);
                sb.Append(
"},");
            }
            sb.Remove(sb.ToString().Length 
- 11);
            sb.Append(
"}");
            Console.WriteLine(sb);
        }
posted @ 2009-12-16 17:38  leeolevis  阅读(244)  评论(0)    收藏  举报