YavorGrancharov

User_Logins(dict)

Jul 9th, 2017
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.42 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace User_Logins
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             List<string> input = Console.ReadLine().Split(' ').ToList();
  12.             Dictionary<string, string> sequences = new Dictionary<string, string>();
  13.  
  14.             while (input[0] != "login")
  15.             {
  16.                 string name = input[0];
  17.                 string password = input[2];
  18.                 if (!sequences.ContainsKey(name))
  19.                 {
  20.                     sequences[name] = password;
  21.                 }
  22.                 input = Console.ReadLine().Split(' ').ToList();
  23.             }
  24.             input = Console.ReadLine().Split(' ').ToList();
  25.  
  26.             int count = 0;
  27.             while (input[0] != "end")
  28.             {
  29.                 string name = input[0];
  30.                 string password = input[2];
  31.                 if (sequences.ContainsKey(name) && sequences.ContainsValue(password))
  32.                 {
  33.                     Console.WriteLine($"{name}: logged in successfully");
  34.                 }
  35.                 else
  36.                 {
  37.                     Console.WriteLine($"{name}: login failed");
  38.                     count++;
  39.                 }
  40.                 input = Console.ReadLine().Split(' ').ToList();
  41.             }
  42.             Console.WriteLine($"unsuccessful login attempts: {count}");
  43.         }
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment