Advertisement
Aborigenius

Pallindrome

Aug 22nd, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.58 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Diagnostics;
  7.  
  8. namespace MiniLab
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             string[] text = Console.ReadLine().Split(new string[] { " ", ",", ".", "?", "!" }, StringSplitOptions.RemoveEmptyEntries);
  15.             SortedSet<string> orderedText = new SortedSet<string>();
  16.             foreach (var word in text)
  17.             {
  18.                 if (IsPalindrome(word))
  19.                 {
  20.                     orderedText.Add(word);
  21.                 }
  22.  
  23.             }
  24.             foreach (var word in orderedText)
  25.             {
  26.                 if (word != orderedText.Last())
  27.                 {
  28.                     Console.Write(word + ", ");
  29.              
  30.                 }
  31.                 else
  32.                 {
  33.                     Console.Write(word);
  34.                 }
  35.                
  36.             }
  37.  
  38.         }
  39.  
  40.         public static bool IsPalindrome(string text)
  41.         {
  42.             int min = 0;
  43.             int max = text.Length - 1;
  44.             while (true)
  45.             {
  46.                 if (min > max)
  47.                 {
  48.                     return true;
  49.                 }
  50.                 char a = text[min];
  51.                 char b = text[max];
  52.                 //      if (char.ToLower(a) != char.ToLower(b))
  53.                 if (a !=  b)
  54.                 {
  55.                     return false;
  56.                 }
  57.                 min++;
  58.                 max--;
  59.             }
  60.         }
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement