Advertisement
nikiman8888

Pilandrome Exam

May 26th, 2018
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.77 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Globalization;
  5. using System.Text.RegularExpressions;
  6.  
  7. namespace lab3.PhoenxGrid
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string input = Console.ReadLine();
  14.             Regex valid = new Regex(@"^([^\s_]{3})([\.]{1}[^\s_]{3})*$");
  15.            
  16.             while(input != "ReadMe")
  17.             {
  18.                 if (valid.IsMatch(input))
  19.                 {
  20.                    
  21.                     if (isPilandrome(input))
  22.                     {
  23.                         Console.WriteLine("YES");
  24.                     }
  25.                     else
  26.                     {
  27.                         Console.WriteLine("NO");
  28.                     }
  29.                 }
  30.                 else
  31.                 {
  32.                     Console.WriteLine("NO");
  33.                 }
  34.                
  35.                 input = Console.ReadLine();
  36.             }
  37.         }
  38.  
  39.         private static bool isPilandrome(string input)
  40.         {
  41.             int count = 0;
  42.             int startIndex = 0;
  43.             int lastIndex = input.Length - 1;
  44.             for (int i = 0; i < input.Length; i++)
  45.             {
  46.                 char start = input[startIndex];
  47.                 char last = input[lastIndex];
  48.  
  49.                if (input[startIndex] != input[lastIndex])
  50.                 {
  51.                     return false;
  52.                 }
  53.                 else
  54.                 {
  55.                     count++;
  56.                     startIndex++;
  57.                     lastIndex--;
  58.                 }
  59.                 if (count == input.Length / 2)
  60.                 {
  61.                     break;
  62.                 }
  63.             }
  64.             return true;
  65.         }
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement