Advertisement
Alexandr0v

From Left To The Right

Jun 25th, 2024
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.09 KB | Source Code | 0 0
  1. using System;
  2. using System.Numerics;
  3. using System.Linq;
  4.  
  5. class Program
  6. {
  7.     static void Main()
  8.     {
  9.         int n = int.Parse(Console.ReadLine());
  10.  
  11.         for (int i = 1; i <= n; i++)
  12.         {
  13.             BigInteger leftSum = 0;
  14.             BigInteger rightSum = 0;
  15.             string number = Console.ReadLine();
  16.  
  17.             // Split the input string into two parts
  18.             string[] sides = number.Split();
  19.             BigInteger leftSide = BigInteger.Parse(sides[0]);
  20.             BigInteger rightSide = BigInteger.Parse(sides[1]);
  21.  
  22.             if (leftSide > rightSide)
  23.             {
  24.                 while (leftSide > 0)
  25.                 {
  26.                     leftSum += leftSide % 10;
  27.                     leftSide /= 10;
  28.                 }
  29.  
  30.                 Console.WriteLine(leftSum);
  31.             }
  32.             else
  33.             {
  34.                 while (rightSide > 0)
  35.                 {
  36.                     rightSum += rightSide % 10;
  37.                     rightSide /= 10;
  38.                 }
  39.  
  40.                 Console.WriteLine(rightSum);
  41.             }
  42.         }
  43.     }
  44. }
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement