Advertisement
Guest User

02. From Leftto TheRight

a guest
Jan 28th, 2020
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.22 KB | None | 0 0
  1. using System;
  2.  
  3. namespace FromLefttoTheRight
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int count = int.Parse(Console.ReadLine());
  10.             string currentNum;
  11.             string leftNum = string.Empty;
  12.             string rightNum = string.Empty;
  13.             int space = 0;
  14.             int minus = 0;
  15.             int leftSum = 0;
  16.             int rightSum = 0;
  17.             int symbolAsInteger;
  18.  
  19.             for (int i = 0; i < count; i++)
  20.             {
  21.                 currentNum = Console.ReadLine();
  22.                 for (int index = 0; index < currentNum.Length; index++)
  23.                 {
  24.                     char symbol = currentNum[index];
  25.                     string symbolAsString = symbol.ToString();                
  26.                     while (true)
  27.                     {
  28.                         if (symbol == ' ')
  29.                         {
  30.                             space++;
  31.                             break;
  32.                         }                    
  33.                         else if (symbol == '-')
  34.                         {
  35.                             minus++;
  36.                             break;
  37.                         }      
  38.                         if (space == 0 && minus == 1 || space == 0 && minus == 0)
  39.                         {          
  40.                             leftNum += symbol;
  41.                             symbolAsInteger = int.Parse(symbolAsString);
  42.                             leftSum += symbolAsInteger;
  43.                             break;
  44.                         }
  45.                         else
  46.                         {
  47.                             rightNum += symbol;
  48.                             symbolAsInteger = int.Parse(symbolAsString);
  49.                             rightSum += symbolAsInteger;
  50.                             break;
  51.                         }                
  52.                     }
  53.                 }
  54.                 if (leftSum > rightSum)
  55.                     Console.WriteLine(leftSum);
  56.                 else
  57.                     Console.WriteLine(rightSum);
  58.                 space = 0;
  59.                 minus = 0;
  60.                 leftSum = 0;
  61.                 rightSum = 0;
  62.             }
  63.         }
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement