📜  流畅的句子 c# 代码示例

📅  最后修改于: 2022-03-11 14:49:00.345000             🧑  作者: Mango

代码示例1
public static bool IsSmooth(string sentence)
{
    sentence = sentence.Trim().ToLower();
    string[] sentences = sentence.Split(' ');

    if (sentence.Length <= 1) return false;

    for (int i = 0; i < sentences.Length - 1; i++)
    {
        string previousWord = sentences[i];
        char lastChar = Char.Parse(previousWord.Substring(previousWord.Length - 1));

        string followingWord = sentences[i + 1];
        char firstChar = Char.Parse(followingWord.Substring(0, 1));

        if (lastChar != firstChar) return false;
    }

    return true;
}