using System.Linq;publicclassKata{publicstaticobject[]Mean(char[] lst)=>newobject[]{
lst.Where(c=>char.IsDigit(c)).Select(c=>c-'0').Average(),newstring(lst.Where(c=>!char.IsDigit(c)).ToArray()),};}
publicclassKata{publicstaticobject[]Mean(char[] lst){double sum =0.0;string concat ="";for(int i =0; i < lst.Length; i++){if(lst[i]>='0'&& lst[i]<='9'){
sum += lst[i]-'0';}else{
concat += lst[i];}}returnnewobject[]{sum/10.0, concat };}}
答案7:
using System.Text;publicclassKata{publicstaticobject[]Mean(char[] lst){double sum =0;var sb =newStringBuilder();foreach(var ch in lst){if(char.IsNumber(ch)){
sum +=double.Parse(ch.ToString());continue;}
sb.Append(ch);}var mean = sum /10;returnnewobject[]{ mean, sb.ToString()};}}
答案8:
publicclassKata{publicstaticobject[]Mean(char[] lst){int sum =0;string str =string.Empty;foreach(char c in lst )if("0123456789".IndexOf( c )!=-1)
sum += c -'0';else
str += c;returnnewobject[]{
sum /10.0,
str
};}}
答案9:
using System;using System.Linq;publicclassKata{publicstaticobject[]Mean(char[] lst){string word =string.Join("", lst.Where(c =>!char.IsDigit(c)));double meam = lst.Where(c =>char.IsDigit(c)).Select(c =>char.GetNumericValue(c)).Average();returnnewobject[2]{meam, word};}}
答案10:
using System.Text;publicclassKata{publicstaticobject[]Mean(char[] lst){var sb =newStringBuilder();int len =0;double digits =0.0;foreach(var i in lst){if(i >='0'&& i <='9'){
digits += i -'0';
len +=1;}else
sb.Append(i);}returnnewobject[]{digits/len, sb.ToString()};}}