Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace _08.Palindromes
- {
- class Program
- {
- static void Main(string[] args)
- {
- char[] separators = { ' ','.','?','!',',' };
- string text = Console.ReadLine();
- var words = text.Split(separators, StringSplitOptions.RemoveEmptyEntries).ToList().Distinct();
- var resultSortedWords = new List<string>();
- foreach (var w in words)
- {
- bool isPalindrome = true;
- for (int i = 0; i < w.Length / 2; i++)
- {
- if (w[i] != w[w.Length - i - 1])
- {
- isPalindrome = false;
- }
- }
- if (isPalindrome)
- {
- resultSortedWords.Add(w);
- }
- }
- resultSortedWords.Sort();
- Console.WriteLine(string.Join(", ",resultSortedWords));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment