Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- namespace _01_Nikulden_s_Charity
- {
- class Program
- {
- static void Main(string[] args)
- {
- string input = Console.ReadLine();
- string[] commands = Console.ReadLine().Split(" ");
- string command = commands[0];
- while (command != "Finish")
- {
- switch (command)
- {
- case "Replace":
- char currentChar = char.Parse(commands[1]);
- char newChar = char.Parse(commands[2]);
- input = input.Replace(currentChar, newChar);
- Console.WriteLine(input);
- break;
- case "Cut":
- int startIndex = int.Parse(commands[1]);
- int endIndex = int.Parse(commands[2]);
- int length = endIndex - startIndex + 1;
- if (startIndex >= 0 && startIndex < input.Length && endIndex > 0 && endIndex <= input.Length)
- {
- input = input.Remove(startIndex, length);
- Console.WriteLine(input);
- }
- else
- {
- Console.WriteLine("Invalid indexes!");
- }
- break;
- case "Make":
- string upOrLo = commands[1];
- if (upOrLo == "Upper")
- {
- input = input.ToUpper();
- Console.WriteLine(input);
- }
- else if (upOrLo == "Lower")
- {
- input = input.ToLower();
- Console.WriteLine(input);
- }
- break;
- case "Check":
- string checkString = commands[1];
- if (input.Contains(checkString))
- {
- Console.WriteLine($"Message contains {checkString}");
- }
- else
- {
- Console.WriteLine($"Message doesn't contain {checkString}");
- }
- break;
- case "Sum":
- startIndex = int.Parse(commands[1]);
- endIndex = int.Parse(commands[2]);
- length = endIndex - startIndex + 1;
- string newSubString = "";
- int sum = 0;
- if (startIndex >= 0 && startIndex < input.Length && endIndex > 0 && endIndex <= input.Length)
- {
- newSubString = input.Substring(startIndex, length);
- for (int i = 0; i < newSubString.Length; i++)
- {
- sum += newSubString[i];
- }
- Console.WriteLine(sum);
- }
- else
- {
- Console.WriteLine("Invalid indexes!");
- }
- break;
- }
- commands = Console.ReadLine().Split(" ");
- command = commands[0];
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement