Advertisement
milislavski

SymbolToNumber

Apr 19th, 2016
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.21 KB | None | 0 0
  1. using System;
  2. using System.Text;
  3.  
  4. class SymbolToNumber
  5. {
  6.     static void Main()
  7.     {
  8.         int secretNumber = int.Parse(Console.ReadLine());
  9.         string text = Console.ReadLine();
  10.         byte[] asciiBytes = Encoding.ASCII.GetBytes(text);
  11.         long result = 0;
  12.         double finalResult = 0;
  13.         for (int i = 0; i < text.Length; i++)
  14.         {
  15.             if (text[i] == '@')
  16.             {
  17.                 break;
  18.             }
  19.             else if ((text[i] >= 'A' && text[i] <= 'Z') || (text[i] >= 'a' && text[i] <= 'z'))
  20.             {
  21.                 result = (asciiBytes[i] * secretNumber) + 1000;
  22.             }
  23.             else if (text[i] >= '0' && text[i] <= '9')
  24.             {
  25.                 result = asciiBytes[i] + secretNumber + 500;
  26.             }
  27.             else
  28.             {
  29.                 result = asciiBytes[i] - secretNumber;
  30.             }
  31.             if (i % 2 == 0)
  32.             {
  33.                 finalResult = (result / 100.0);
  34.                 Console.WriteLine("{0:F2}", finalResult);
  35.             }
  36.             else
  37.             {
  38.                 finalResult = result * 100;
  39.                 Console.WriteLine(finalResult);
  40.             }
  41.  
  42.         }
  43.  
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement