using System.Collections.Generic;publicclassDeadfish{publicstaticint[]Parse(string program){var output =newList<int>();intvalue=0;foreach(var instruction in program){switch(instruction){case'i':++value;break;case'd':--value;break;case's':value*=value;break;case'o':
output.Add(value);break;}}return output.ToArray();}}
using System.Collections.Generic;publicclassDeadfish{publicstaticint[]Parse(string data){int i =0;
List<int> result =newList<int>();foreach(char c in data){if(c =='i') i++;elseif(c =='d') i--;elseif(c =='s') i*= i;elseif(c =='o') result.Add(i);}return result.ToArray();}}
答案4:
using System;using System.Collections.Generic;publicclassDeadfish{publicstaticint[]Parse(string data){int total =0;
List<int> res =newList<int>();for(int i =0; i< data.Length; i++){if(data[i]=='i'){ total +=1;}elseif(data[i]=='d'){ total -=1;}elseif(data[i]=='s'){ total =(int)Math.Pow(total,2);}elseif(data[i]=='o'){res.Add(total);}elsecontinue;}return res.ToArray();}}
答案5:
using System.Collections.Generic;publicclassDeadfish{publicstaticint[]Parse(string data){
List<int> values =newList<int>();intvalue=0;for(int i =0; i < data.Length; i++){char letter = data[i];switch(letter){case'i':value=value+1;break;case'd':value=value-1;break;case's':value=value*value;break;case'o':
values.Add(value);break;}}return values.ToArray();}}
答案6:
using System.Collections.Generic;publicclassDeadfish{publicstaticint[]Parse(string data){
List<int> values =newList<int>();int value1 =0;foreach(char c in data){switch(c){case'i':// Increment the value
value1++;break;case'd':// Decrement the value
value1--;break;case's':// Square the value
value1 *= value1;break;case'o':// Add value to array
values.Add(value1);break;default:break;}}return values.ToArray();}}
答案7:
publicclassDeadfish{publicstaticint[]Parse(string data){int index =0;int occ =0;int iteration =0;foreach(char c in data){if(c =='o'){
index++;}}int[] res =newint[index];foreach(char d in data){if(d =='i'){
occ++;}elseif(d =='d'){
occ--;}elseif(d =='s'){
occ = occ * occ;}elseif(d =='o'){
res[iteration]= occ;
iteration++;}}return res;}}
答案8:
using System;using System.Collections.Generic;publicclassDeadfish{publicstaticint[]Parse(string data){var arr =newList<int>();var r =0;foreach(var x in data){switch(x){case'i':
r++;break;case'd':
r--;break;case's':
r = r * r;break;case'o':
arr.Add(r);break;default:break;}}return arr.ToArray();}}
答案9:
using System.Collections.Generic;publicclassDeadfish{publicstaticint[]Parse(string data){// Return the output array, and ignore all non-op characters
List<int> res =newList<int>();booladd=false;intvalue=0;foreach(char val in data){switch(val){case'i':value++;break;case'd':value--;break;case's':value*=value;break;case'o':
res.Add(value);break;}}return res.ToArray();}}
答案10:
using System;using System.Collections.Generic;publicclassDeadfish{publicstaticint[]Parse(string data){char[] dataCommands = data.ToCharArray();int number =0;
List<int> output =newList<int>();for(int i=0; i<dataCommands.Length; i++){if(dataCommands[i]=='i') number++;elseif(dataCommands[i]=='d') number--;elseif(dataCommands[i]=='s') number = number * number;elseif(dataCommands[i]=='o') output.Add(number);}return output.ToArray();}}
使Deadfish游泳【难度:2级】:答案1:using System.Collections.Generic;public class Deadfish{ public static int[] Parse(string program) { var output = new List<int>(); int value = 0; ...