Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Globalization;
- using System.Runtime.InteropServices;
- namespace ConsoleApp2
- {
- class Program
- {
- static void Main(string[] args)
- {
- char[] input = Console.ReadLine().ToCharArray();
- Array.Sort(input);
- int singleCounter = 0;
- int indexSingle = input.Length-1;
- char before = input[0];
- bool madeCouple = false;
- bool even = false;
- bool successful = false;
- //Even
- if (input.Length % 2 == 0)
- {
- even = true;
- for (int i = 1; i < input.Length; i++)
- {
- if (madeCouple)
- {
- before = input[i];
- madeCouple = false;
- }
- else
- {
- char now = input[i];
- if (now == before)
- {
- madeCouple = true;
- }
- else
- {
- Console.WriteLine("No");
- return;
- }
- }
- }
- Console.WriteLine("Yes");
- successful = true;
- }
- //Odd
- else
- {
- for (int i = 1; i < input.Length; i++)
- {
- if (madeCouple)
- {
- before = input[i];
- madeCouple = false;
- }
- else
- {
- char now = input[i];
- if (now == before)
- {
- madeCouple = true;
- }
- else
- {
- before = input[i];
- indexSingle = i-1;
- singleCounter++;
- }
- }
- }
- if (singleCounter > 1)
- {
- Console.WriteLine("No");
- }
- else
- {
- Console.WriteLine("Yes");
- successful = true;
- }
- }
- if (successful)
- {
- char[] palindrome = new char[input.Length];
- if (even)
- {
- int counter = 0;
- for (int i = 0; i < palindrome.Length; i++)
- {
- if (i % 2 == 0)
- {
- palindrome[counter] = input[i];
- counter++;
- }
- else
- {
- palindrome[^counter] = input[i];
- }
- }
- }
- else
- {
- int counter = 0;
- int iCounter = 0;
- for (int i = 0; i < palindrome.Length; i++)
- {
- if (indexSingle == i)
- {
- int index = palindrome.Length / 2 ;
- palindrome[index] = input[i];
- continue;
- }
- if (iCounter % 2 == 0)
- {
- palindrome[counter] = input[i];
- counter++;
- }
- else
- {
- palindrome[^counter] = input[i];
- }
- iCounter++;
- }
- }
- foreach (var letter in palindrome)
- {
- Console.Write(letter);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement