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;
- using System.Runtime.InteropServices;
- using System.Data;
- using System.IO;
- using System.Reflection.PortableExecutable;
- namespace _02._Boss_Rush
- {
- class Program
- {
- static void Main(string[] args)
- {
- string input = Console.ReadLine();
- string[] command = Console.ReadLine().Split();
- while (command[0] != "Finish")
- {
- if (command[0] == "Replace")
- {
- if (input.Contains(command[1]))
- {
- input = input.Replace(command[1], command[2]);
- }
- }
- if (command[0] == "Cut")
- {
- int index = int.Parse(command[1]);
- int end = int.Parse(command[2]);
- if ((index >= 0 && index < input.Length) && end >= 0 && end < input.Length)
- {
- int lenght = end - index + 1;
- input = input.Remove(index, lenght);
- }
- else
- {
- Console.WriteLine("Invalid indexes!");
- command = Console.ReadLine().Split();
- continue;
- }
- }
- if (command[0] == "Make")
- {
- if (command[1] == "Upper")
- {
- input = input.ToUpper();
- }
- else
- {
- input = input.ToLower();
- }
- }
- if (command[0] == "Check")
- {
- if (input.Contains(command[1]))
- {
- Console.WriteLine($"Message contains {command[1]}");
- command = Console.ReadLine().Split();
- continue;
- }
- else
- {
- Console.WriteLine($"Message doesn't contain {command[1]}");
- command = Console.ReadLine().Split();
- continue;
- }
- }
- if (command[0] == "Sum")
- {
- int start = int.Parse(command[1]);
- int end = int.Parse(command[2]);
- if ((start >= 0 && start < input.Length) && end >= 0 && end < input.Length)
- {
- int lenght = end - start + 1;
- string sub = input.Substring(start, lenght);
- char[] subs = sub.ToCharArray();
- int sum = 0;
- foreach (var item in subs)
- {
- sum += item;
- }
- Console.WriteLine(sum);
- command = Console.ReadLine().Split();
- continue;
- }
- else
- {
- Console.WriteLine("Invalid indexes!");
- command = Console.ReadLine().Split();
- continue;
- }
- }
- Console.WriteLine(input);
- command = Console.ReadLine().Split();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement