Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Text;
- using System.Collections.Generic;
- namespace exercise
- {
- class MainClass
- {
- public static void Main()
- {
- string[] text = Console.ReadLine()
- .Split(new char[]{' ', ',', '.', '!', '?'},StringSplitOptions.RemoveEmptyEntries);
- Array.Sort(text);
- List<string> result = new List<string>();
- foreach (var word in text)
- {
- if(IsPalindrom(word))
- {
- if (result.Contains(word))
- {
- continue;
- }
- result.Add(word);
- }
- }
- Console.WriteLine(String.Join(", ", result));
- }
- public static bool IsPalindrom(string s)
- {
- for (int i = 0; i < s.Length/2; i++)
- {
- if (s[i] != s[s.Length -i -1])
- {
- return false;
- }
- }
- return true;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement