csharp基础练习题:查找组合【难度:1级】--景越C#经典编程题库,不同难度C#练习题,适合自学C#的新手进阶训练

csharp基础练习题:查找组合【难度:1级】:

你的目标是计数的字母或符号某个词或组合出现了多少次在字符串中.关键是不区分大小写,可以在字符串中出现的许多或几十倍.该函数声明为您提供的并且应该有两个参数与返回计数一个返回变量.叠词不应该算作一次以上!空字符串不能是一个关键.该功能还应该能算整数和字符数.认真想!

例:

countCombinations("我的名字叫比利和比利是真棒","比利"); // 2
countCombinations( 'abcdefghijklmonopolymonorailqrstuv', '单'); // 2
countCombinations( 'GrEggreGGREGgREG', '格雷格'); // 4
countCombinations( '@#$ ## @@@', '@'); // 4
countCombinations( '哇什么', '是的'); // 0
countCombinations( 'lololololol', '洛尔'); // 3
countCombinations( '93049', '\\ d'); // 5
countCombinations( '五', '\'); // 5

Kata.CountCombinations("我的名字叫比利和比利是真棒","比利"); // 2
Kata.CountCombinations( "abcdefghijklmonopolymonorailqrstuv", "单声道"); // 2
Kata.CountCombinations( "GrEggreGGREGgREG", "格雷格"); // 4
Kata.CountCombinations( "@#$ ## @@@", "@"); // 4
Kata.CountCombinations( "哇什么", "是啊"); // 0
Kata.CountCombinations( "lololololol", "笑"); // 3
Kata.CountCombinations( "93049",@ "\\ d"); // 5
Kata.CountCombinations( "五个一",@ "\"); // 5

请给予反馈和排名!这将是惊人的!

编程目标:

public class Kata
{
  public static int CountCombinations(string text, string key)
  {
    return 0;
  }
}


测试样例:

namespace Solution 
{
  using NUnit.Framework;
  using System;  
  [TestFixture]
  public class KataTests
  {
    [Test]
      Assert.AreEqual(3, Kata.CountCombinations("hellohellohello", "hello"), "Try again! These words don't need spaces in between.");
    }
  }
}


最佳答案(多种解法):

点击查看答案

更多关联题目:

csharp基础练习题:温度分析我【难度:1级】–景越C# 经典编程题库,不同难度C# 练习题,适合自学C# 的新手进阶训练

免责申明

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

上一篇:kata application mount


下一篇:csharp基础练习题:简单有趣#154:零和一【难度:1级】--景越C#经典编程题库,不同难度C#练习题,适合自学C#的新手进阶训练