Advertisement
Guest User

Untitled

a guest
Jan 28th, 2021
487
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.93 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 linesNumber = int.Parse(Console.ReadLine());
  10.             //long sum = 0L;
  11.  
  12.             //string leftNum = "";
  13.             //string rightNum = "";
  14.            
  15.             for (int i = 0; i < linesNumber; i++)
  16.             {
  17.                 string leftNum = "";
  18.                 string rightNum = "";
  19.                 int sumOfDigits = 0;
  20.  
  21.                 string input = Console.ReadLine();
  22.  
  23.                 int j = 0;
  24.  
  25.                 while (input[j] != ' ')
  26.                 {
  27.                     leftNum += input[j];
  28.                     j ++;
  29.                 }
  30.                 while ((j + 1) != input.Length)
  31.                 {
  32.                     rightNum += input[j+1];
  33.                     j++;
  34.                 }
  35.  
  36.                 long left = long.Parse(leftNum);
  37.                 long right = long.Parse(rightNum);
  38.  
  39.                 if (left >= right)
  40.                 {
  41.                     for (int k = leftNum.Length; k >= 0; k--)
  42.                     {
  43.                         byte lastDigits = 0;
  44.                         lastDigits = (byte)(Math.Abs(left % 10));
  45.                         sumOfDigits += (int)lastDigits;
  46.                         left /= 10;
  47.                     }
  48.                     Console.WriteLine(sumOfDigits);
  49.                 }
  50.                 else
  51.                 {
  52.                     for (int k = rightNum.Length; k >= 0; k--)
  53.                     {
  54.                         byte lastDigits = 0;
  55.                         lastDigits = (byte)(Math.Abs(right % 10));
  56.                         sumOfDigits += (int)lastDigits;
  57.                         right /= 10;
  58.                     }
  59.                    
  60.                     Console.WriteLine(sumOfDigits);
  61.                 }
  62.             }
  63.            
  64.             // Console.WriteLine(rightNum);
  65.         }
  66.     }
  67. }
  68.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement