2017-03-04 9 views
-3
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"); 
      } 
      } 
      } 
      } 
       } 

私はこれを試しましたが、入力文字列を取りたいとすべての文字列のためには、文字列が回文かどうかを返しますWAPは、文字列が回文かどうかをC#で確認します。

+0

可能重複9790749 /文字列であるかどうかを確認する文字列 – Xavave

+0

可能なテストケースを手助けするだけです –

+0

隠されたテストケース?真剣に? – Sefe

答えて

0

あなたが可能なテストケースによって意味を理解してわからない:私は3つの文字列を使用して、コードを変更してテストしてみた :

「coucou」:パリンドロームなし

"のカヤック":回文

"abcdeffedcba":回文

、それが今で正常に動作します:http://stackoverflow.com/questions/から

palindrome

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(); 
    } 
+0

入力として空文字列を取るとどうなりますか? –

+0

空の文字列を入力として受け取った場合はYESを返しますが、この特殊な場合はnoを返すことをお勧めします。if(!string.IsNullOrEmpty(strTestCases [nTestCase])&& strTestCases [nTestCase] SequenceEqual(strTestCases [nTestCase] .Reverse())) – Xavave

関連する問題