Advertisement
abushik

Password Reset

Apr 6th, 2020
1,114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.24 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Text;
  4.  
  5. namespace Problem_1._Password_Reset
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             string password = Console.ReadLine();
  12.             string input;
  13.             string oddText = string.Empty;
  14.             while ((input = Console.ReadLine()) != "Done")
  15.             {
  16.                 string[] split = input.Split();
  17.  
  18.                 string command = split[0];
  19.                 if (command == "TakeOdd")
  20.                 {
  21.                     for (int i = 1; i < password.Length; i += 2)
  22.                     {
  23.                         oddText += password[i];
  24.                     }
  25.                     password = oddText;
  26.                     Console.WriteLine(password);
  27.                     //result = string.Concat(password.Where((c, i) => i % 2 != 0));
  28.                     //Console.WriteLine(result);
  29.                 }
  30.                 //Cut 15 3
  31.                 if (command == "Cut")
  32.                 {
  33.                     int index = int.Parse(split[1]);
  34.                     int lenght = int.Parse(split[2]);
  35.                     if (!(index >= password.Length || lenght > password.Length))
  36.                     {
  37.                         password = password.Remove(index, lenght);
  38.                         //result = result.Substring(0, index) + result.Substring(lenght + 1);
  39.                         Console.WriteLine(password);
  40.  
  41.                     }
  42.                     else
  43.                     {
  44.                         break;
  45.                     }
  46.                 }
  47.                 //Substitute :: -
  48.                 if (command == "Substitute")
  49.                 {
  50.                     string substring = split[1];
  51.                     string substitute = split[2];
  52.  
  53.                     if (password.Contains(substring))
  54.                     {
  55.  
  56.                         password = password.Replace(substring, substitute);
  57.                         Console.WriteLine(password);
  58.                     }
  59.                     else
  60.                     {
  61.                         Console.WriteLine("Nothing to replace!");
  62.                     }
  63.                 }
  64.             }
  65.             Console.WriteLine($"Your password is: {password}");
  66.         }
  67.     }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement