Advertisement
silvana1303

nikulden charity

Aug 6th, 2020
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.56 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. using System.Text.RegularExpressions;
  5. using System.Runtime.InteropServices;
  6. using System.Data;
  7. using System.IO;
  8. using System.Reflection.PortableExecutable;
  9.  
  10. namespace _02._Boss_Rush
  11. {
  12.     class Program
  13.     {
  14.         static void Main(string[] args)
  15.         {
  16.             string input = Console.ReadLine();
  17.  
  18.             string[] command = Console.ReadLine().Split();
  19.  
  20.             while (command[0] != "Finish")
  21.             {
  22.                 if (command[0] == "Replace")
  23.                 {
  24.                     if (input.Contains(command[1]))
  25.                     {
  26.                         input = input.Replace(command[1], command[2]);
  27.                     }
  28.                 }
  29.                 if (command[0] == "Cut")
  30.                 {
  31.                     int index = int.Parse(command[1]);
  32.                     int end = int.Parse(command[2]);
  33.                     if ((index >= 0 && index < input.Length) && end >= 0 && end < input.Length)
  34.                     {
  35.                         int lenght = end - index + 1;
  36.                         input = input.Remove(index, lenght);
  37.                     }
  38.                     else
  39.                     {
  40.                         Console.WriteLine("Invalid indexes!");
  41.                         command = Console.ReadLine().Split();
  42.                         continue;
  43.                     }
  44.              
  45.                 }
  46.                 if (command[0] == "Make")
  47.                 {
  48.                     if (command[1] == "Upper")
  49.                     {
  50.                         input = input.ToUpper();
  51.                     }
  52.                     else
  53.                     {
  54.                         input = input.ToLower();
  55.                     }
  56.                 }
  57.                 if (command[0] == "Check")
  58.                 {
  59.                     if (input.Contains(command[1]))
  60.                     {
  61.                         Console.WriteLine($"Message contains {command[1]}");
  62.                         command = Console.ReadLine().Split();
  63.                         continue;
  64.                     }
  65.                     else
  66.                     {
  67.                         Console.WriteLine($"Message doesn't contain {command[1]}");
  68.                         command = Console.ReadLine().Split();
  69.                         continue;
  70.                     }
  71.                 }
  72.                 if (command[0] == "Sum")
  73.                 {
  74.                     int start = int.Parse(command[1]);
  75.                     int end = int.Parse(command[2]);
  76.  
  77.                     if ((start >= 0 && start < input.Length) && end >= 0 && end < input.Length)
  78.                     {
  79.                         int lenght = end - start + 1;
  80.                         string sub = input.Substring(start, lenght);
  81.                         char[] subs = sub.ToCharArray();
  82.                         int sum = 0;
  83.  
  84.                         foreach (var item in subs)
  85.                         {
  86.                             sum += item;
  87.                         }
  88.                         Console.WriteLine(sum);
  89.  
  90.                         command = Console.ReadLine().Split();
  91.                         continue;
  92.                     }
  93.                     else
  94.                     {
  95.                         Console.WriteLine("Invalid indexes!");
  96.                         command = Console.ReadLine().Split();
  97.                         continue;
  98.                     }
  99.                 }
  100.  
  101.                 Console.WriteLine(input);
  102.                 command = Console.ReadLine().Split();
  103.             }
  104.         }
  105.     }
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement