Menu
CoddyTech

图案查找器

本课属于 Coddy C# 学习旅程的“基础知识”单元。第 68 课,共 69 课。

challenge icon

挑战

简单

编写一个程序,接收两个字符串数组作为输入,并判断第二个数组是否以连续顺序出现在第一个数组中。

当第二个数组的所有元素按相同顺序连续出现在第一个数组的某个位置时,就表示存在这样的模式,就像在一个字符串中查找子字符串一样。

例如:

string str1 = {"1", "2", "3", "4", "5", "6", "7"};
string str2 = {"3", "4", "5"};
// Should return true
string str1 = {"5", "6", "7", "8", "9"};
string str2 = {"6", "8"};
// Should return false (not consecutive)

亲手试试

using System;

public class Program {
    public static void Main(string[] args) {
        string arrString1 = Console.ReadLine();
        string arrString2 = Console.ReadLine();
        string[] str1 = arrString1.Split(",");
        string[] str2 = arrString2.Split(",");
        // 在下方编写你的代码
        
    }
}

基础知识中的所有课

自己练习: C# 在线编译器