字符串必须拆分为4个配对不同的非空白部分。例如,将字符串N拆分为4个不同的字符串
"happynewyear"
可以成为["happy", "new", "ye" and "ar"
]
没有缺失,字符的顺序变化是允许的。
这个问题是网络竞赛的一部分,现在已经结束。我已经写了下面的C#代码,它适用于我已经运行的测试用例,但在提交之后,它在3个测试用例中失败。我不知道我可能会错过哪些情况,有谁能帮忙?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Hackerearth___India_Hacks
{
class Program
{
static void Main(string[] args)
{
var line1 = System.Console.ReadLine().Trim();
var N = Int32.Parse(line1);
string[] s = new string[N];
string result = "";
for (var i = 0; i < N; i++)
{
s[i] = System.Console.ReadLine().Trim();
result = result + "\n" + check(s[i]);
}
System.Console.Write(result);
Console.ReadKey();
}
static string check(string s)
{
if (s.Length > 3)
{
string[] s1 = new string[4];
int k = 0;
string c = "";
foreach (char ch in s)
{
c = c + ch.ToString();
// Console.WriteLine("C :" +c);
if (k == 0)
{
s1[k] = c;
c = "";
k = 1;
}
else
for (int i = 0; i < k; i++)
{
int f = 0;
for (int j = 0; j < k; j++)
{
if (s1[j].Equals(c) || c == "")
f=1;
}
if (f == 1)
break;
s1[k] = c;
c = "";
if (k == 3 && s1[k] != null)
return "YES";
k++;
// Console.WriteLine("K :"+s[k]);
}
}
return "NO";
}
else
{
return "NO";
}
}
}
}
您的问题缺少链接到竞争问题和什么是有效的,什么不可行的例子,即输入和预期的输出。 –
它失败的输入是什么,这些输入的预期输出是什么? – wentimo
我想我找到了原始网站的链接https://www.hackerearth.com/problem/algorithm/string-division/ – juharr