Advertisement
Guest User

Untitled

a guest
Oct 26th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Collections;
  7.  
  8. namespace ConsoleApplication2
  9. {
  10. class Program
  11. {
  12. public static Dictionary<char, int> getChar2Number()
  13. {
  14. string alfabet = "ёйцукенгшщзхъфывапролджэячсмитьбю";
  15. char[] alfabetArray = new char[33];
  16. for (int i = 0; i < 33; i++)
  17. {
  18. alfabetArray[i] = alfabet[i];
  19. }
  20. Array.Sort(alfabetArray);
  21. Dictionary<char, int> char2Number = new Dictionary<char, int>();
  22. for (int i = 0; i < 33; i++)
  23. {
  24. char2Number.Add(alfabetArray[i], i+1);
  25. }
  26. return char2Number;
  27. }
  28. static void Main(string[] args)
  29. {
  30. var char2Number = getChar2Number();
  31. //Можешь убрать цикл, если нужна одна аутентификация
  32. while (true)
  33. {
  34. Console.WriteLine("Привет, как тебя зовут?");
  35. var name = Console.ReadLine();
  36. Console.WriteLine("Введи номер для аутентификации");
  37. int n = int.Parse(Console.ReadLine());
  38. int expectedN = 0;
  39. foreach (char c in name)
  40. {
  41. expectedN += char2Number[c];
  42. }
  43. if (expectedN == n)
  44. {
  45. Console.WriteLine("Вход выполнен успешно");
  46. }
  47. else
  48. {
  49. Console.WriteLine("Кажется, что-то пошло не так :(");
  50. Console.WriteLine("Попробуем еще раз.");
  51. }
  52.  
  53. }
  54. }
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement