fk4m1913

Untitled

May 29th, 2020
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.39 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 linesCount = int.Parse(Console.ReadLine());
  10.  
  11.             for (int line = 0; line < linesCount; line++)
  12.             {
  13.                 string number = Console.ReadLine();
  14.                 string leftNum = "";
  15.                 string rightNum = "";
  16.                 long biggerNum = 0;
  17.                 long numberSum = 0;
  18.                 int counter = -1;
  19.  
  20.                 for (int i = 0; i < number.Length; i++)
  21.                 {
  22.                     counter++;
  23.                     char symbol = number[i];
  24.  
  25.                     if (symbol == ' ')
  26.                     {
  27.                         break;
  28.                     }
  29.  
  30.                     leftNum += symbol;
  31.                 }
  32.  
  33.                 for (int i = counter + 1; i < number.Length; i++)
  34.                 {
  35.                     char symbol = number[i];
  36.                     rightNum += symbol;
  37.                 }
  38.  
  39.                 biggerNum = Math.Max(Convert.ToInt64(leftNum), Convert.ToInt64(rightNum));
  40.  
  41.                 while (Math.Abs(biggerNum) > 0)
  42.                 {
  43.                     numberSum += Math.Abs(biggerNum) % 10;
  44.                     biggerNum = Math.Abs(biggerNum) / 10;
  45.                 }
  46.  
  47.                 Console.WriteLine(numberSum);
  48.             }
  49.         }
  50.     }
  51. }
Add Comment
Please, Sign In to add comment