Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text.RegularExpressions;
- namespace Regexs
- {
- class Program
- {
- static void Main(string[] args)
- {
- int[] array = Console.ReadLine().Split(", ").Select(int.Parse).ToArray(); //change to split by comma and space
- int startIndex = int.Parse(Console.ReadLine()); //read index of entry point
- int number = array[startIndex]; //take element on entry point position
- string input = Console.ReadLine();
- int leftcheapsum = 0;
- int rightcheapsum = 0;
- int leftexpensivesum = 0;
- int rightexpensivesum = 0;
- for (int i = 0; i < array.Length; i++)
- {
- if (input == "cheap")
- {
- if (array[i] < number)
- {
- if (i < startIndex) //change to compare current index to starting index
- {
- leftcheapsum = leftcheapsum + array[i];
- }
- if (i > startIndex) //change to compare current index to starting index
- {
- rightcheapsum = rightcheapsum + array[i];
- }
- }
- }
- if (input == "expensive")
- {
- if (array[i] >= number)
- {
- if (i < startIndex) //change to compare current index to starting index
- {
- leftexpensivesum = leftexpensivesum + array[i];
- }
- if (i > startIndex) //change to compare current index to starting index
- {
- rightexpensivesum = rightexpensivesum + array[i];
- }
- }
- }
- }
- if (input == "cheap")
- {
- if (leftcheapsum >= rightcheapsum)
- {
- Console.WriteLine($"left - {leftcheapsum}");
- }
- else
- {
- Console.WriteLine($"right - {rightcheapsum}");
- }
- }
- if (input == "expensive")
- {
- if (leftexpensivesum >= rightexpensivesum)
- {
- Console.WriteLine($"left - {leftexpensivesum}");
- }
- else
- {
- Console.WriteLine($"right - {rightexpensivesum}");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement