Advertisement
MyOnAsSalat

Untitled

Dec 10th, 2017
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.18 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Runtime.CompilerServices;
  4. public class Program
  5. {
  6.     public static void Main()
  7.     {        
  8.         Console.WriteLine("Введите строку: ");
  9.         char[] s = Console.ReadLine().ToCharArray();    
  10.         if (!isInt(s[0])) { if (isInt(s[s.Length - 1])) { Answer(false); return; } }
  11.         if (isInt(s[0])) { if (!isInt(s[s.Length - 1])) { Answer(false); return; } }
  12.         bool buf = isInt(s[0]);
  13.         Answer(s.Skip(1).All(x => { bool BufBool = buf != isInt(x); buf = isInt(x); return BufBool; }));
  14.     }
  15.     // аттрибут указывает компилятору, что по возможности необходимо заинлайнить код метода в месте вызова, а не вызвать по ссылке
  16.     [MethodImpl(MethodImplOptions.AggressiveInlining)]
  17.     public static void Answer(bool a){Console.WriteLine(a? "Строка удовлетворяет условию" : "Строка не удовлетворяет условию");}
  18.     [MethodImpl(MethodImplOptions.AggressiveInlining)]
  19.     public static bool isInt (char a) {return int.TryParse(a.ToString(), out int d);}
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement