字符串必須拆分爲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