Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Text.RegularExpressions;
- namespace ConsoleApp1
- {
- class Program
- {
- static void Main(string[] args)
- {
- Boolean isUnlogin = true;
- while (isUnlogin)
- {
- Regex groupRegexp = new Regex(@"[а-я, А-Я]{1,3}-\d+");
- Console.WriteLine("Введите название группы: ");
- string groupNumber = Console.ReadLine();
- while (!groupRegexp.IsMatch(groupNumber))
- {
- Console.WriteLine("Название группы неверно");
- groupNumber = Console.ReadLine();
- }
- int firstDigitIndex = groupNumber.IndexOf("-") + 1;
- string number = groupNumber.Substring(firstDigitIndex, groupNumber.Length - firstDigitIndex);
- int sum = 0;
- foreach (char digit in number)
- {
- sum += (int)char.GetNumericValue(digit);
- }
- string rigthPassword = sum.ToString();
- Console.WriteLine("Введите пароль: ");
- string password = Console.ReadLine();
- if (password == rigthPassword)
- {
- Console.WriteLine("Вход выполнен успешно");
- isUnlogin = false;
- }
- else
- {
- Console.WriteLine("Логин или пароль неверен.");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement