交替字符串
using System;
public class Test
{
//我的check函数明明都已经实现了交替字符串的验证功能,为嘛,结果说我的输出格式与标准不同
public static string check(String str1, String str2, String str3)
{
int i = 0, j = 0, k = 0;
while (i < str1.Length || j < str2.Length)
{
if (k == str3.Length) return "NO";
if (i < str1.Length && str1[i] == str3[k])
{
i++;
k++;
}
else if (j < str2.Length && str2[j] == str3[k])
{
j++;
k++;
}
else return "NO";
}
if (i == str1.Length && j == str2.Length && k == str3.Length)
return "YES";
else return "NO";
}
public static void Main()
{
string str1, str2, str3;
str1 = "asdfg";
str2 = "fhjk";
str3 = "asdffhjkg";
Console.WriteLine(check(str1, str2, str3));
//Console.WriteLine("输入样例\nabc\ndef\nabdecf");
//Console.WriteLine("abc\ndef\nabdecfg\n");
//Console.WriteLine("输出样例");
//Console.WriteLine(check("abc", "def", "abdecf"));
//Console.WriteLine(check("abc", "def", "abdecfg"));
//Console.WriteLine(check(Console.ReadLine(), Console.ReadLine(), Console.ReadLine()));
//Console.WriteLine(check(Console.ReadLine(), Console.ReadLine(), Console.ReadLine()));
}
}