Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace Pa_indromes
- {
- class Program
- {
- static void Main()
- {
- string[] inputParams = Console.ReadLine().Split(new char[] { ' ', '\t', ',', '?', '!', '.' }, StringSplitOptions.RemoveEmptyEntries);
- List<string> palindromes = new List<string>();
- for (int i = 0; i < inputParams.Length; i++)
- {
- string word = inputParams[i];
- if (word.Length == 1)
- {
- palindromes.Add(word);
- } else if(word.Length % 2 == 1)
- {
- bool sidesMatches = true;
- int middleCharacter = word.Length / 2;
- for (int j = 0; j < middleCharacter; j++)
- {
- if (word[middleCharacter - (1 + j)] != word[middleCharacter + (1 + j)])
- {
- sidesMatches = false;
- break;
- }
- }
- if (sidesMatches)
- {
- palindromes.Add(word);
- }
- } else
- {
- bool sidesMatches = true;
- int middleCharacter = word.Length / 2;
- for (int j = 0; j < middleCharacter; j++)
- {
- if (word[middleCharacter - (1 + j)] != word[middleCharacter + j])
- {
- sidesMatches = false;
- break;
- }
- }
- if (sidesMatches)
- {
- palindromes.Add(word);
- }
- }
- }
- palindromes.Sort((a, b) => a.CompareTo(b));
- Console.WriteLine("[" + string.Join(", ", palindromes) + "]");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement