tanya_zheleva

8

Feb 18th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.30 KB | None | 0 0
  1. using System;
  2. using System.Text.RegularExpressions;
  3.  
  4. namespace ExamPreparation
  5. {
  6.     public sealed class Preparation
  7.     {
  8.         public static void Main()
  9.         {
  10.            string[] tokens = Console.ReadLine().Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
  11.            double totalSum = 0;
  12.             string pattern = @"([a-zA-z])(\d+)([a-zA-Z])";
  13.  
  14.             foreach (var token in tokens)
  15.             {
  16.                 Match match = Regex.Match(token, pattern);
  17.                 char letterBefore = match.Groups[1].Value[0];
  18.                 double number = double.Parse(match.Groups[2].Value);
  19.                 char letterAfter = match.Groups[3].Value[0];
  20.  
  21.                 if (char.IsLower(letterBefore))
  22.                 {
  23.                     number *= (letterBefore - 96);
  24.                 }
  25.                 else
  26.                 {
  27.                     number /= (letterBefore - 64);
  28.                 }
  29.  
  30.                 if (char.IsLower(letterAfter))
  31.                 {
  32.                     number += (letterAfter - 96);
  33.                 }
  34.                 else
  35.                 {
  36.                     number -= (letterAfter - 64);
  37.                 }
  38.  
  39.                 totalSum += number;
  40.             }
  41.  
  42.             Console.WriteLine($"{totalSum:F2}");
  43.         }
  44.     }
  45. }
Add Comment
Please, Sign In to add comment