Advertisement
Guest User

Untitled

a guest
Mar 9th, 2023
539
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.97 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5.  
  6. namespace Regexs
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             int[] array = Console.ReadLine().Split(", ").Select(int.Parse).ToArray();   //change to split by comma and space
  13.             int startIndex = int.Parse(Console.ReadLine());                             //read index of entry point
  14.             int number = array[startIndex];                                             //take element on entry point position
  15.             string input = Console.ReadLine();
  16.             int leftcheapsum = 0;
  17.             int rightcheapsum = 0;
  18.             int leftexpensivesum = 0;
  19.             int rightexpensivesum = 0;
  20.  
  21.             for (int i = 0; i < array.Length; i++)
  22.             {
  23.  
  24.                 if (input == "cheap")
  25.                 {
  26.                     if (array[i] < number)
  27.                     {
  28.                         if (i < startIndex)                                             //change to compare current index to starting index
  29.                         {
  30.  
  31.                             leftcheapsum = leftcheapsum + array[i];
  32.  
  33.                         }
  34.                         if (i > startIndex)                                             //change to compare current index to starting index
  35.                         {
  36.  
  37.                             rightcheapsum = rightcheapsum + array[i];
  38.  
  39.                         }
  40.                     }
  41.  
  42.                 }
  43.                 if (input == "expensive")
  44.                 {
  45.                     if (array[i] >= number)
  46.                     {
  47.                         if (i < startIndex)                                             //change to compare current index to starting index
  48.                         {
  49.  
  50.                             leftexpensivesum = leftexpensivesum + array[i];
  51.  
  52.                         }
  53.                         if (i > startIndex)                                             //change to compare current index to starting index
  54.                         {
  55.  
  56.                             rightexpensivesum = rightexpensivesum + array[i];
  57.  
  58.                         }
  59.                     }
  60.  
  61.                 }
  62.  
  63.             }
  64.             if (input == "cheap")
  65.             {
  66.                 if (leftcheapsum >= rightcheapsum)
  67.                 {
  68.                     Console.WriteLine($"left - {leftcheapsum}");
  69.                 }
  70.                 else
  71.                 {
  72.                     Console.WriteLine($"right - {rightcheapsum}");
  73.                 }
  74.             }
  75.             if (input == "expensive")
  76.             {
  77.                 if (leftexpensivesum >= rightexpensivesum)
  78.                 {
  79.                     Console.WriteLine($"left - {leftexpensivesum}");
  80.                 }
  81.                 else
  82.                 {
  83.                     Console.WriteLine($"right - {rightexpensivesum}");
  84.                 }
  85.             }
  86.         }
  87.     }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement