Advertisement
Stanislav2812

Untitled

Aug 23rd, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.96 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 YaYunior4
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.  
  14.             char symbol = Convert.ToChar(Console.ReadLine());
  15.             Console.WriteLine((int)symbol);            
  16.             Console.WriteLine(Translate(symbol, 31));
  17.             Console.WriteLine(Translate('а', 50) == 'т');
  18.             Console.WriteLine(Translate('я', -3) == 'ь');
  19.             Console.WriteLine(Translate('а', -3) == 'э'); //
  20.             Console.WriteLine(Translate('б', -3) == 'ю'); //
  21.             Console.WriteLine(Translate('б', 32) == 'б');
  22.             Console.WriteLine(Translate('б', -32) == 'б');
  23.             Console.WriteLine(Translate('б', 33) == 'в');
  24.             Console.WriteLine(Translate('б', -33) == 'а');
  25.             Console.WriteLine(Translate('б', 34) == 'г');
  26.             Console.WriteLine(Translate('б', -34) == 'я'); //
  27.             Console.WriteLine(Translate('б', 64) == 'б');
  28.             Console.WriteLine(Translate('б', -64) == 'б');
  29.  
  30.            
  31.         }
  32.  
  33.         static char Translate(char symbol, int translation, char min = 'а', char max = 'я')
  34.         {
  35.            
  36.             int current = (int)symbol + (translation % 32);            
  37.             return symbol = Convert.ToChar(Clamp(current, (int)min, (int)max));
  38.         }
  39.  
  40.         static int Clamp(int current, int min, int max)
  41.         {
  42.             int translate;
  43.             if ((current > (int)max))
  44.                             {
  45.                             translate = (int)min + current - (int)max;
  46.                             }
  47.                         else
  48.                         {
  49.                             translate = current > (int)min ? current : (int)max - ((int)min - current) ;
  50.                         }          
  51.                        return current = translate;
  52.         }
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement