using System.Text.RegularExpressions;using System.Linq;publicstaticclassKata{publicstaticintCountSmileys(string[] smileys){return smileys.Count(s => Regex.IsMatch(s,@"^[:;]{1}[~-]{0,1}[\)D]{1}$"));}}
答案2:
using System.Text.RegularExpressions;publicstaticclassKata{publicstaticintCountSmileys(string[] smileys)=> Regex.Matches(string.Join(" ",smileys),"([:;][-~]?)[)D]").Count;}
答案3:
using System.Collections.Generic;using System.Linq;using System;publicstaticclassKata{publicstaticintCountSmileys(string[] smileys){int c =0;
List<string> smileysList = smileys.ToList<string>();
List<char> eyes =newList<char>{':',';'};
List<char> nose =newList<char>{'-','~'};
List<char> mouth =newList<char>{')','D'};foreach(string str in smileys){if(str.Length==2|| str.Length ==3){if(eyes.Exists(symbol => symbol.Equals(str.First<char>()))){if(mouth.Exists((symbol => symbol.Equals(str.Last<char>())))){if(nose.Exists(symbol=> symbol.Equals(str.ElementAt<char>(1))))
c++;elseif(str.Length ==2)
c++;}}}}return c;}}
答案4:
publicstaticclassKata{publicstaticintCountSmileys(string[] s){int num =0;for(int i=0; i<s.Length;++i){if(s[i].Length ==2){if(s[i][0]==':'|| s[i][0]==';')if(s[i][1]==')'|| s[i][1]=='D')
num = num +1;}elseif(s[i].Length ==3){if(s[i][0]==':'|| s[i][0]==';')if(s[i][1]=='-'|| s[i][1]=='~')if(s[i][2]==')'|| s[i][2]=='D')
num = num +1;}}// С# AUTHORS PLEASE DDDIIIIEEEEE!!!!!!!!!!!!!!!!!!!!!!!!!!!11111111111111return num;}}
答案5:
using System.Linq;using System.Text.RegularExpressions;publicstaticclassKata{privatestaticreadonlyRegex SmileyRegex =newRegex(@"^[:;][-~]?[)D]$");publicstaticintCountSmileys(string[] smileys){return smileys.Count(SmileyRegex.IsMatch);}}
答案6:
using System.Text.RegularExpressions;using System.Linq;publicstaticclassKata{privatestaticRegex regex =newRegex(@"^[:;][-~]?[)D]$");privatestaticintIsSmiley(string smiley)=>
regex.Match(smiley).Success ?1:0;publicstaticintCountSmileys(string[] smileys)=>
smileys.Sum(IsSmiley);}
答案7:
using System;using System.Text.RegularExpressions;using System.Collections.Generic;publicstaticclassKata{publicstaticintCountSmileys(string[] smileys){Regex r =newRegex("[:;][-~]?[)D]");int Count =0;foreach(string smile in smileys){if(r.IsMatch(smile)){++Count;}}return Count;}}
答案8:
using System;publicstaticclassKata{publicstaticintCountSmileys(string[] smileys){int count =0;foreach(string smiley in smileys){if(((smiley.Contains(':')|| smiley.Contains(';')))&&((smiley.Contains(')')|| smiley.Contains('D')))&&!smiley.Contains(' '))
count++;}return count;}}
答案9:
using System.Linq;publicstaticclassKata{publicstaticintCountSmileys(string[] smileys){// Probablu not a recommended approach.// Best to instead use regular expresionsstring[] validSmileys ={":)",";)",":D",";D",":-)",":-D",":~)",":~D",";-)",";~)",";-D",";~D",};return smileys.Count(s => validSmileys.Contains(s));}}
答案10:
using System.Linq;using System.Text.RegularExpressions;publicstaticclassKata{publicstaticintCountSmileys(string[] smileys){return smileys.Count(x=>Regex.IsMatch(x,@"^[:;][-~]?[)D]$"));}}
答案11:
using System.Linq;using System.Text.RegularExpressions;publicstaticclassKata{publicstaticintCountSmileys(string[] smileys){return smileys.Count(x => Regex.IsMatch(x,@"^[;:][-~]?[)D]$"));}}