Advertisement
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 _7.Palindromes
- {
- class Program
- {
- static void Main(string[] args)
- {
- char[] delimiters = new char[] { ' ', ',', '?', '!', '.', ':' };
- string[] text = Console.ReadLine().Split(delimiters, StringSplitOptions.RemoveEmptyEntries).ToArray();
- string wordToCheck = "";
- List<string> palindromes = new List<string>();
- for (int word = 0; word < text.Length; word++)
- {
- wordToCheck = text[word];
- if (wordToCheck.Length == 1)
- {
- palindromes.Add(wordToCheck);
- }
- for (int pal = 0; pal < wordToCheck.Length / 2; pal++)
- {
- if (wordToCheck[pal] == wordToCheck[wordToCheck.Length - 1])
- {
- palindromes.Add(wordToCheck);
- }
- } //end of for
- }//end of for
- palindromes = palindromes.Distinct().ToList();
- palindromes.Sort();
- Console.WriteLine(string.Join(", ", palindromes));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement