using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PelindromeIdentifier
{
class Program
{
static void Main()
{
int nNumberOfTestCases = 0;
int.TryParse(Console.ReadLine(), out nNumberOfTestCases);
String[] strTestCases = new String[nNumberOfTestCases];
char[] arrChar;
int nCharCount = 0;
bool bAllow = false;
int nCharIndex = 0;
for (int nTestCase = 0; nTestCase < nNumberOfTestCases; nTestCase++)
{
strTestCases[nTestCase] = Console.ReadLine();
}
for (int nTestCase = 0; nTestCase < nNumberOfTestCases; nTestCase++)
{
bAllow = false;
arrChar = strTestCases[nTestCase].Distinct().ToArray();
for (nCharIndex = 0; nCharIndex < arrChar.Length; nCharIndex++)
{
nCharCount = strTestCases[nTestCase].Count(i => i.Equals(arrChar[nCharIndex]));
if (strTestCases[nTestCase].Length % 2 == 0)
{
if (nCharCount % 2 != 0)
{
Console.WriteLine("NO");
break;
}
}
else
{
if (nCharCount % 2 != 0)
{
if (bAllow == true)
{
Console.WriteLine("NO");
break;
}
bAllow = true;
}
}
}
if (nCharIndex == arrChar.Length)
{`
Console.WriteLine("YES");
}
}
}
}
}
我尝试了这个,但有一些隐藏的测试用例无法正常工作。任何人都可以帮助我吗?在这个程序中,程序会询问用户你想要输入多少次输入字符串,并且对于每个字符串它将返回是否为字符串是不是回文
答案 0 :(得分:0)
不确定可能的测试用例是什么意思: 我已经更改了您的代码并使用3个字符串进行了测试:
&#34; coucou&#34; :不是回文
&#34;皮艇&#34; :回文
&#34; abcdeffedcba&#34; :回文
现在工作正常:
static void Main()
{
int nNumberOfTestCases = 0;
var input =
int.TryParse(Console.ReadLine(), out nNumberOfTestCases);
String[] strTestCases = new String[nNumberOfTestCases];
for (int nTestCase = 0; nTestCase < nNumberOfTestCases; nTestCase++)
{
strTestCases[nTestCase] = Console.ReadLine();
}
for (int nTestCase = 0; nTestCase < nNumberOfTestCases; nTestCase++)
{
if (strTestCases[nTestCase].SequenceEqual(strTestCases[nTestCase].Reverse()))
Console.WriteLine("YES");
else
Console.WriteLine("NO");
}
Console.ReadKey();
}