using System.Linq;publicstaticclassKata{publicstaticstringBabel(int n)=>string.Join("\n",Enumerable.Range(0,n*3).Select(i=>newstring(' ',n-1-(int)(i/3))+newstring('o',2*(int)(i/3)+1)));}
using System.Collections.Generic;publicstaticclassKata{privateconstint LayersCount =3;publicstaticstringBabel(int height){var tower =newList<string>(height * LayersCount);for(int i =0; i < height; i++){for(int j =0; j < LayersCount; j++){
tower.Add($"{new string(' ', height - i - 1)}{new string('o', i)}o{new string('o', i)}");}}returnstring.Join("\n", tower);}}
答案4:
using System;using System.Collections.Generic;publicstaticclassKata{publicstaticstringBabel(int height){if(height ==0){return"";}else{
List<string> result =newList<string>(height *3);for(int x =0; x < height; x++){for(int y =0; y <3; y++){
result.Add(newstring(' ', height - x -1)+newstring('o', x *2+1));}}return String.Join("\n", result);}}}
答案5:
using System.Collections.Generic;publicstaticclassKata{publicstaticstringBabel(int height ){var floors =newList<string>( height*3);for(int i =0; i < height; i++){var floor =newstring(' ', height - i -1)+newstring('o',2*i +1);
floors.Add( floor );
floors.Add( floor );
floors.Add( floor );}returnstring.Join("\n", floors );}}
答案6:
using System.Collections.Generic;publicstaticclassKata{publicstaticstringBabel(int height){if(height ==0)return"";var l =newList<string>();for(int i =0; i < height; i++)for(int y =0; y <3; y++)
l.Add(newstring(' ', height - i -1)+newstring('o', i *2+1));returnstring.Join("\n", l);}}
答案7:
using System.Text;using System;publicstaticclassKata{publicstaticstringBabel(int height){StringBuilder tower =newStringBuilder(String.Empty);for(int i =1; i <= height; i++){int spaces = height - i;int oes =(i *2)-1;
tower.Append(' ', spaces).Append('o', oes).Append("\n");
tower.Append(' ', spaces).Append('o', oes).Append("\n");
tower.Append(' ', spaces).Append('o', oes);if(i != height) tower.Append("\n");}return tower.ToString();}}
答案8:
using System.Linq;publicstaticclassKata{publicstaticstringBabel(int height){if(height ==0){return"";}int width =2* height -1;returnstring.Join("\n", Enumerable.Range(0, height).SelectMany(i => Enumerable.Repeat(newstring('o',2*i +1).PadLeft(width/2+ i +1,' '),3)));}}
答案9:
using System;using System.Text;publicstaticclassKata{publicstaticstringBabel(int height){StringBuilder a =newStringBuilder();int k;for(int i =1; i <= height; i++){
k = i *2-1;for(int j =0; j <3; j++){
a.Append(newstring(' ', height - i)+newstring('o', k)+'\n');}}return Convert.ToString(a).TrimEnd('\n');}}
答案10:
using System;using System.Text;using System.Collections.Generic;publicstaticclassKata{publicstaticstringBabel(int height){var str =newList<string>();for(int i =0; i < height; i++){for(int j =0; j <3; j++){var sb =newStringBuilder();for(int k =0; k < height - i -1; k++){
sb.Append(" ");}for(int k =0; k < i *2+1; k++){
sb.Append("o");}
str.Add(sb.ToString());}}returnstring.Join("\n", str);}}