csharp进阶练习题:对象列表形式的等式【难度:2级】--景越C#经典编程题库,不同难度C#练习题,适合自学C#的新手进阶训练

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/weixin_45444821/article/details/100587339

csharp进阶练习题:对象列表形式的等式【难度:2级】:

您的任务是在** 对象列表上编写扩展方法** 并返回一个整数来求解方程式.
List 包括整数和字符串以及Null.

List 的格式如下:

[外链图片转存失败(img-KIDvdgpe-1567778231976)(http://crowd-multilogue.com/Images/Codewars/KataPic.png"Logo Title Text 1")]

List  objectList = new List (){2," - ",82,"+",802,"+",62," - ",23," - ",924,"+", 1,"+",200,"+",null,"+",102,"+",300," - ",10,"=",924};

null是红色框,你必须找到整数来解决方程式.
数字是整数,运算符("+"," - “,”=")是字符串.

编程目标:

namespace BlankExtention {
using System;
using System.Collections.Generic;
using System.Linq;
  public static class Kata
    {
        public static int CalculateBlank(this List objectList)
        {
            //Happy Coding
        }
    }
}


测试样例:

namespace BlankExtention {
  using NUnit.Framework;
  using System.Collections.Generic;
  using System.Linq;
  using System;
  [TestFixture]
    public class MyTest
    {
        {
            List objectList = new List() { 2, "-", 82, "+", 802, "+", 62, "-", 23, "-", 924, "+", 1, "+", 200, "+", null, "+", 102, "+", 300, "-", 10, "=", 924 };
            Assert.AreEqual(494,objectList.CalculateBlank());
        }
        [Test]
        public void SecondTest()


最佳答案(多种解法):

点击查看答案

更多关联题目:

免责申明

本博客所有编程题目及答案均收集自互联网,主要用于供网友学习参考,如有侵犯你的权益请联系管理员及时删除,谢谢
题目收集至https://www.codewars.com/
https://www.codewars.com/kata/equation-in-form-of-objects-list

猜你喜欢

转载自blog.csdn.net/weixin_45444821/article/details/100587339