publicclassKata{publicstaticstringMyFirstInterpreter(string code){byte memory =0;string stdout ="";foreach(char c in code){if(c =='+')++memory;if(c =='.') stdout +=(char)memory;}return stdout;}}
答案2:
using System.Text;publicclassKata{publicstaticstringMyFirstInterpreter(string code){var output =newStringBuilder();byte memory =0;foreach(char c in code){switch(c){case'+':++memory;break;case'.':
output.Append((char)memory);break;}}return output.ToString();}}
答案3:
using System;publicclassKata{publicstaticstringMyFirstInterpreter(string code){string output ="";byte buffer =0;foreach(char c in code.ToCharArray()){switch(c){case'+':try{
buffer++;}catch(Exception){
buffer =0;}break;case'.':
output +=(char)buffer;break;default:break;}}return output;}}
答案4:
publicclassKata{publicstaticstringMyFirstInterpreter(string code){var flag =0;var result =string.Empty;foreach(var c in code){switch(c){case'+':
flag++;if(flag ==256) flag =0;break;case'.':
result +=((char)flag).ToString();break;default:break;}}return result;}}
答案5:
using System.Linq;using System;publicclassKata{publicstaticstringMyFirstInterpreter(string code){byte memory =0;return String.Join("", code.Select(x=>x.ToString()).Select(x=>{if(x=="+"){memory++;}elseif(x=="."){return((char)memory).ToString();}return"";}));}}
答案6:
using System.Collections.Generic;using System.Linq;publicclassKata{publicstaticstringMyFirstInterpreter(string code)=>newstring(MiniStringFuck(code).ToArray());privatestatic IEnumerable<char>MiniStringFuck(string code){byte cell =0;foreach(var instruction in code){if(instruction =='+') cell++;if(instruction =='.')yieldreturn(char)cell;}}}
答案7:
publicclassKata{publicstaticstringMyFirstInterpreter(string code){byte cell =default(byte);string output =string.Empty;foreach(char command in code){switch(command)//not 'if' because with 'switch' you can easier add new features to this code{case'+':unchecked{ cell++;}break;case'.':
output +=(char)cell;break;}}return output;}}
答案8:
using System;publicclassKata{publicstaticstringMyFirstInterpreter(string code){
code = code.Replace(((char)13).ToString(),"");char[] chars = code.ToCharArray();int cell=0;string output="";foreach(char c in chars){if(c=='+'){if(cell==255) cell=0;else cell++;}elseif(c=='.') output+=Convert.ToChar(cell);}return output;}}
答案9:
using System;using System.Collections.Generic;publicclassKata{publicstaticstringMyFirstInterpreter(string code){string result ="";int cell =0;foreach(char character in code){if(character =='+'){if(cell ==255){
cell =0;}else{++cell;}}else{if(character =='.'){
result = String.Concat(result +(char)cell);}}}return result;}}
答案10:
using System;using System.Text;publicclassKata{publicstaticstringMyFirstInterpreter(string code){var builder =newStringBuilder();byte memory =0;foreach(var c in code){if(c =='+')++memory;elseif(c =='.')
builder.Append(Convert.ToChar(memory));}return builder.ToString();}}