Advertisement
Guest User

Untitled

a guest
Mar 31st, 2020
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.68 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace _01_Nikulden_s_Charity
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             string input = Console.ReadLine();
  11.             string[] commands = Console.ReadLine().Split(" ");
  12.             string command = commands[0];
  13.  
  14.             while (command != "Finish")
  15.             {
  16.                 switch (command)
  17.                 {
  18.                     case "Replace":
  19.                         char currentChar = char.Parse(commands[1]);
  20.                         char newChar = char.Parse(commands[2]);
  21.                         input = input.Replace(currentChar, newChar);
  22.                        
  23.                         Console.WriteLine(input);
  24.                         break;
  25.                     case "Cut":
  26.                         int startIndex = int.Parse(commands[1]);
  27.                         int endIndex = int.Parse(commands[2]);
  28.                         int length = endIndex - startIndex + 1;
  29.  
  30.                         if (startIndex >= 0 && startIndex < input.Length && endIndex > 0 && endIndex <= input.Length)
  31.                         {
  32.                             input = input.Remove(startIndex, length);
  33.  
  34.                             Console.WriteLine(input);
  35.                         }
  36.                         else
  37.                         {
  38.                             Console.WriteLine("Invalid indexes!");
  39.                         }
  40.                         break;
  41.                     case "Make":
  42.                         string upOrLo = commands[1];
  43.                        
  44.                         if (upOrLo == "Upper")
  45.                         {
  46.                             input = input.ToUpper();
  47.                            
  48.                             Console.WriteLine(input);
  49.                         }
  50.  
  51.                         else if (upOrLo == "Lower")
  52.                         {
  53.                             input = input.ToLower();
  54.  
  55.                             Console.WriteLine(input);
  56.                         }
  57.                         break;
  58.                     case "Check":
  59.                         string checkString = commands[1];
  60.  
  61.                         if (input.Contains(checkString))
  62.                         {
  63.                             Console.WriteLine($"Message contains {checkString}");
  64.                         }
  65.                         else
  66.                         {
  67.                             Console.WriteLine($"Message doesn't contain {checkString}");
  68.                         }
  69.                         break;
  70.                     case "Sum":
  71.                         startIndex = int.Parse(commands[1]);
  72.                         endIndex = int.Parse(commands[2]);
  73.                         length = endIndex - startIndex + 1;
  74.                         string newSubString = "";
  75.                         int sum = 0;
  76.  
  77.                         if (startIndex >= 0 && startIndex < input.Length && endIndex > 0 && endIndex <= input.Length)
  78.                         {
  79.                             newSubString = input.Substring(startIndex, length);
  80.  
  81.                             for (int i = 0; i < newSubString.Length; i++)
  82.                             {
  83.                                 sum += newSubString[i];
  84.                             }
  85.                            
  86.                             Console.WriteLine(sum);
  87.                         }
  88.                         else
  89.                         {
  90.                             Console.WriteLine("Invalid indexes!");
  91.                         }
  92.                         break;
  93.                 }
  94.  
  95.                 commands = Console.ReadLine().Split(" ");
  96.                 command = commands[0];
  97.             }
  98.         }
  99.     }
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement