Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- using System.Text.RegularExpressions;
- namespace Problem_1._Activation_Keys_FinalExam_04._04._20
- {
- class Program
- {
- static void Main(string[] args)
- {
- string key = Console.ReadLine();
- string input = "";
- while ((input = Console.ReadLine()) != "Generate")
- {
- string[] splittedIn = input.Split(">>>");
- string command = splittedIn[0];
- if (command == "Contains")
- {
- string substr = splittedIn[1];
- if (key.Contains(substr))
- {
- Console.WriteLine($"{key} contains {substr}");
- }
- else
- {
- Console.WriteLine("Substring not found!");
- }
- }
- else if (command == "Flip")
- {
- string secCom = splittedIn[1];
- if (secCom == "Upper")
- {
- int startIndex = int.Parse(splittedIn[2]);
- int endIndex = int.Parse(splittedIn[3]);
- if (startIndex >= 0 && endIndex >= 0 && endIndex <= key.Length)
- {
- int length = endIndex - startIndex;
- string newStr = key.Substring(startIndex, length).ToUpper();
- key = key.Replace(key.Substring(startIndex, length), newStr);
- Console.WriteLine(key);
- }
- }
- else if (secCom == "Lower")
- {
- int startIndex = int.Parse(splittedIn[2]);
- int endIndex = int.Parse(splittedIn[3]);
- if (startIndex >= 0 && endIndex >= 0 && endIndex <= key.Length)
- {
- int length = endIndex - startIndex;
- string newStr = key.Substring(startIndex, length).ToLower();
- key = key.Replace(key.Substring(startIndex, length), newStr);
- Console.WriteLine(key);
- }
- }
- }
- else if (command == "Slice")
- {
- int startIndex = int.Parse(splittedIn[1]);
- int endIndex = int.Parse(splittedIn[2]);
- if (startIndex >= 0 && endIndex >= 0 && endIndex <= key.Length)
- {
- int length = endIndex - startIndex;
- //string newStr = key.Substring(startIndex, length);
- key = key.Remove(startIndex, length);
- Console.WriteLine(key);
- }
- }
- }
- Console.WriteLine($"Your activation key is: {key}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement