Advertisement
Guest User

Untitled

a guest
Nov 19th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.61 KB | None | 0 0
  1. using System;
  2. using System.Text.RegularExpressions;
  3.  
  4. namespace ConsoleApp1
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             Boolean isUnlogin = true;
  11.             while (isUnlogin)
  12.             {
  13.                 Regex groupRegexp = new Regex(@"[а-я, А-Я]{1,3}-\d+");
  14.                 Console.WriteLine("Введите название группы: ");
  15.                 string groupNumber = Console.ReadLine();
  16.  
  17.                 while (!groupRegexp.IsMatch(groupNumber))
  18.                 {
  19.                     Console.WriteLine("Название группы неверно");
  20.                     groupNumber = Console.ReadLine();
  21.                 }
  22.  
  23.                 int firstDigitIndex = groupNumber.IndexOf("-") + 1;
  24.                 string number = groupNumber.Substring(firstDigitIndex, groupNumber.Length - firstDigitIndex);
  25.  
  26.                 int sum = 0;
  27.                 foreach (char digit in number)
  28.                 {
  29.                     sum += (int)char.GetNumericValue(digit);
  30.                 }
  31.  
  32.                 string rigthPassword = sum.ToString();
  33.  
  34.                 Console.WriteLine("Введите пароль: ");
  35.                 string password = Console.ReadLine();
  36.                 if (password == rigthPassword)
  37.                 {
  38.                     Console.WriteLine("Вход выполнен успешно");
  39.                     isUnlogin = false;
  40.                 }
  41.                 else
  42.                 {
  43.                     Console.WriteLine("Логин или пароль неверен.");
  44.                 }
  45.             }
  46.  
  47.         }
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement