daily pastebin goal
25%
SHARE
TWEET

Palindroms

EmoRz Jun 13th, 2018 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Palindroms
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             List<string> input = Console.ReadLine().Split(new[] {' ', ',', '.', '?', '!' }, StringSplitOptions.RemoveEmptyEntries).ToList();
  12.             //
  13.             List<string> palindroms = new List<string>();
  14.             //
  15.             foreach (var word in input)
  16.             {
  17.                 var currentWord = word;
  18.                 var reversedWord = "";
  19.                 for (int i = word.Length-1; i >= 0 ; i--)
  20.                 {
  21.                     reversedWord += word[i];
  22.                 }
  23.                 if (currentWord == reversedWord)
  24.                 {
  25.                     palindroms.Add(reversedWord);
  26.                 }
  27.                 reversedWord = "";
  28.             }
  29.             Console.WriteLine(string.Join(", ", palindroms.OrderBy(x => x).Distinct()));
  30.         }
  31.     }
  32. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top