anizko

2.From Left to The Right 25/100

May 26th, 2019
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.51 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _02._From_Left_to_The_Right
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int countLines = int.Parse(Console.ReadLine());
  10.             int leftSum = 0;
  11.             int rightSum = 0;
  12.  
  13.             for (int i = 1; i <= countLines; i++)
  14.             {
  15.                 string number = Console.ReadLine();
  16.                 for (int j = 0; j < number.Length; j++)
  17.                 {
  18.                     char symbol = number[j];
  19.  
  20.                     if ((int)symbol != 32)
  21.                     {
  22.                         leftSum += symbol- '0';
  23.                     }
  24.                     else
  25.                     {
  26.                         break;
  27.                     }
  28.                  
  29.                   }
  30.                 for (int k = number.Length-1; k>=0 ; k--)
  31.                 {
  32.                     char symbol = number[k];
  33.  
  34.                     if ((int)symbol != 32)
  35.                     {
  36.                         rightSum += symbol - (int)'0';
  37.                     }
  38.                     else
  39.                     {
  40.                         break;
  41.                     }
  42.              
  43.                 }
  44.                 if (rightSum> leftSum)
  45.                 {
  46.                     Console.WriteLine(rightSum);
  47.                 }
  48.                 else
  49.                 {
  50.                     Console.WriteLine(leftSum);
  51.                 }
  52.                 rightSum = 0;
  53.                 leftSum = 0;
  54.  
  55.             }
  56.  
  57.            
  58.         }
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment