Galin_P87

02. From Left to The Right

Oct 4th, 2018
1,928
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.98 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()
  8.         {
  9.             int n = int.Parse(Console.ReadLine());
  10.  
  11.             for (int i = 0; i < n; i++)
  12.             {
  13.                 string numbers = Console.ReadLine();
  14.                 char delimiter = ' ';
  15.                 string[] splitNumbers = numbers.Split(delimiter);
  16.  
  17.                 long leftNum = long.Parse(splitNumbers[0]);
  18.                 long rightNum = long.Parse(splitNumbers[1]);
  19.  
  20.                 long biggerNumber = rightNum;
  21.                 if (leftNum > rightNum)
  22.                 {
  23.                     biggerNumber = leftNum;
  24.                 }
  25.  
  26.                 long sumOfDigits = 0;
  27.                 while (biggerNumber != 0)
  28.                 {
  29.                     sumOfDigits += biggerNumber % 10;
  30.                     biggerNumber /= 10;
  31.                 }
  32.                 Console.WriteLine(Math.Abs(sumOfDigits));
  33.             }
  34.         }
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment