Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Runtime.CompilerServices;
- public class Program
- {
- public static void Main()
- {
- Console.WriteLine("Введите строку: ");
- char[] s = Console.ReadLine().ToCharArray();
- if (!isInt(s[0])) { if (isInt(s[s.Length - 1])) { Answer(false); return; } }
- if (isInt(s[0])) { if (!isInt(s[s.Length - 1])) { Answer(false); return; } }
- bool buf = isInt(s[0]);
- Answer(s.Skip(1).All(x => { bool BufBool = buf != isInt(x); buf = isInt(x); return BufBool; }));
- }
- // аттрибут указывает компилятору, что по возможности необходимо заинлайнить код метода в месте вызова, а не вызвать по ссылке
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void Answer(bool a){Console.WriteLine(a? "Строка удовлетворяет условию" : "Строка не удовлетворяет условию");}
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool isInt (char a) {return int.TryParse(a.ToString(), out int d);}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement