petaryankov00

02.FromLeftToTheRight

Sep 29th, 2020
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.26 KB | None | 0 0
  1. using System;
  2. using System.Numerics;
  3.  
  4. namespace FromLeftToRight
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             int lineNumbers = int.Parse(Console.ReadLine());
  11.  
  12.             for (int i = 0; i < lineNumbers; i++)
  13.             {
  14.                 string numbers = Console.ReadLine();
  15.  
  16.                 string firstNumberAssString = string.Empty;
  17.                 string secondNumberAssString = string.Empty;
  18.  
  19.                 bool isFirstNumberFound = false;
  20.  
  21.                 for (int j = 0; j < numbers.Length; j++)
  22.                 {
  23.                     char currentDigit = numbers[j];
  24.  
  25.                     if (isFirstNumberFound == false)
  26.                     {
  27.                         if (currentDigit == ' ')
  28.                         {
  29.                             isFirstNumberFound = true;
  30.                         }
  31.                         else
  32.                         {
  33.                             firstNumberAssString += numbers[j];
  34.                         }
  35.                     }
  36.                     else
  37.                     {
  38.                         secondNumberAssString += currentDigit;
  39.                     }
  40.                 }
  41.  
  42.                 BigInteger num1 = BigInteger.Parse(firstNumberAssString);
  43.                 BigInteger num2 = BigInteger.Parse(secondNumberAssString);
  44.  
  45.                 BigInteger digit1 = 0;
  46.                 BigInteger sum1 = 0;
  47.                 while (num1 > 0)
  48.                 {
  49.                     digit1 = num1 % 10;
  50.                     num1 = num1 / 10;
  51.                     sum1 = sum1 + digit1;
  52.  
  53.                 }
  54.  
  55.                 BigInteger digit2 = 0;
  56.                 BigInteger sum2 = 0;
  57.                 while (num2 > 0)
  58.                 {
  59.                     digit2 = num2 % 10;
  60.                     num2 = num2 / 10;
  61.                     sum2 = sum2 + digit2;
  62.                 }
  63.  
  64.                 if (sum1 > sum2)
  65.                 {
  66.                     Console.WriteLine($"{sum1}");
  67.                 }
  68.  
  69.                 else if (sum2 > sum1)
  70.                 {
  71.                     Console.WriteLine($"{sum2}");
  72.                 }
  73.                 else
  74.                 {
  75.                     Console.WriteLine($"{sum1}");
  76.                 }
  77.             }
  78.         }
  79.     }
  80. }
  81.  
Add Comment
Please, Sign In to add comment