Advertisement
Guest User

Untitled

a guest
Mar 24th, 2017
478
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.56 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.Text;
  5. using System.Linq;
  6.  
  7. public class Program
  8. {
  9.     public static void Main()
  10.     {
  11.         var logins = new Dictionary<string, string>();
  12.  
  13.         while (true)
  14.         {
  15.             var command = Console.ReadLine();
  16.  
  17.             if (command == "login")
  18.             {
  19.                 break;
  20.             }
  21.  
  22.             var userInfo = command.Split();
  23.             var username = userInfo[0];
  24.             var password = userInfo[2];
  25.  
  26.             logins[username] = password;
  27.         }
  28.  
  29.         var count = 0;
  30.  
  31.         while (true)
  32.         {
  33.             var command = Console.ReadLine();
  34.  
  35.             if (command == "end")
  36.             {
  37.                 break;
  38.             }
  39.  
  40.             var loginInfo = command.Split();
  41.             var username = loginInfo[0];
  42.             var password = loginInfo[2];
  43.  
  44.             if (!logins.ContainsKey(username))
  45.             {
  46.                 Console.WriteLine($"{username}: login failed");
  47.                 count++;
  48.             }
  49.             else if (logins.ContainsKey(username))
  50.             {
  51.                 if (password == logins[username])
  52.                 {
  53.                     Console.WriteLine($"{username}: logged in successfully");
  54.                 }
  55.                 else
  56.                 {
  57.                     Console.WriteLine($"{username}: login failed");
  58.                     count++;
  59.                 }
  60.             }
  61.         }
  62.  
  63.         Console.WriteLine($"unsuccessful login attempts: {count}");
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement