Advertisement
cap7ainjack

Palindromes

Sep 26th, 2015
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data.SqlClient;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace Hmwrk_3_6
  9. {
  10. class Program
  11. {
  12. static void Main(string[] args)
  13. {
  14. string[] input = Console.ReadLine().Split(',',' ','!','?',' ').ToArray();
  15.  
  16. PalindromChecker(input);
  17.  
  18. }
  19.  
  20. private static void PalindromChecker(string[] array)
  21. {
  22. StringBuilder builder = new StringBuilder();
  23.  
  24. Array.Sort(array);
  25.  
  26. for (int i = 0; i < array.Length; i++)
  27. {
  28. string reversed = StringReverser(array[i]);
  29.  
  30. if (array[i] == reversed)
  31. {
  32. builder.Append(reversed).Append(" ");
  33. }
  34. }
  35. string[] stringedBuilder = builder.ToString().Split(new char[] { ' ' },
  36. StringSplitOptions.RemoveEmptyEntries);
  37.  
  38. Console.WriteLine(string.Join(", ",stringedBuilder));
  39.  
  40. }
  41.  
  42. private static string StringReverser(string strInput)
  43. {
  44. char[] charArray = strInput.ToCharArray();
  45. Array.Reverse(charArray);
  46. return new string(charArray);
  47. }
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement