Advertisement
Guest User

Untitled

a guest
Feb 20th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.45 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Messages
  8. {
  9.     class Program
  10.     {
  11.         static string[] numSystem = { "cad", "xoz", "nop", "cyk", "min", "mar", "kon", "iva", "ogi", "yan"};
  12.  
  13.         static void Main(string[] args)
  14.         {
  15.             string firstStr = Console.ReadLine();
  16.             string op = Console.ReadLine();
  17.             string secondStr = Console.ReadLine();
  18.  
  19.             int firstNum = Decrypt(firstStr);
  20.             int secondNum = Decrypt(secondStr);
  21.  
  22.             int numResult = (op == "+" ? firstNum + secondNum : firstNum - secondNum);
  23.             string result = Encrypt(numResult);
  24.  
  25.             Console.WriteLine(result);
  26.         }
  27.  
  28.         private static string Encrypt(int num)
  29.         {
  30.             string result = "";
  31.             int digit = 0;
  32.  
  33.             while (num > 0)
  34.             {
  35.                 digit = num % 10;
  36.                 result = numSystem[digit] + result;
  37.                 num /= 10;
  38.             }
  39.  
  40.             return result;
  41.         }
  42.  
  43.         private static int Decrypt(string str)
  44.         {
  45.             int result = 0;
  46.             string digit;
  47.             for (int i = 0; i < str.Length; i+=3)
  48.             {
  49.                 digit = str.Substring(i, 3);
  50.                 result = result * 10 + Array.IndexOf(numSystem, digit);
  51.             }
  52.  
  53.             return result;
  54.         }
  55.  
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement