Advertisement
Nikolcho

Gosho tarikatski

Apr 27th, 2020
563
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.29 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace _01._Gosho_tarikatski
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             int code = 0;
  11.             int[] numbers = Console.ReadLine()
  12.                 .Split()
  13.                 .Select(n => int.Parse(n))
  14.                 .ToArray();
  15.  
  16.  
  17.             int place = 1;
  18.             for (int i = 1, j = 3; i <= 3; i++, j--)
  19.             {
  20.                 int currentDigit = GetDigit(numbers[0], i) + GetDigit(numbers[1], j);
  21.                 if (currentDigit > 9)
  22.                 {
  23.                     code += (currentDigit % 10 + currentDigit / 10) * place;
  24.                 }
  25.                 else
  26.                 {
  27.                     code += currentDigit * place;
  28.                 }
  29.                 place *= 10;
  30.             }        
  31.  
  32.             Console.WriteLine(code);
  33.         }
  34.  
  35.         public static int GetDigit(int number, int digitPlace)
  36.         {
  37.  
  38.             switch (digitPlace)
  39.             {
  40.                 case 1:
  41.                     return number % 10;
  42.                 case 2:
  43.                     return number / 10 % 10;
  44.                 case 3:
  45.                     return number / 100;
  46.                 default:
  47.                     return -1;
  48.             }
  49.  
  50.         }
  51.     }
  52.    
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement