Advertisement
ghostd0g

Untitled

Feb 24th, 2018
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.06 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. using System.Numerics;
  7. using System.Text.RegularExpressions;
  8.  
  9. namespace Exercise8
  10. {
  11.     class Program
  12.     {
  13.         static void Main(string[] args)
  14.         {
  15.             string[] input = Console.ReadLine().Split(new char[] {' ','\t'},StringSplitOptions.RemoveEmptyEntries);
  16.  
  17.             decimal result = 0;
  18.  
  19.             for (int i = 0; i < input.Length; i++)
  20.             {
  21.                 string currentString = input[i].Trim();
  22.                 decimal currentResult = 0;
  23.  
  24.                 string pattern = @"([A-Za-z])(\d+)([A-Za-z])";
  25.                 Match groups = Regex.Match(input[i], pattern);
  26.                
  27.  
  28.                 bool isFirstLetterUpper = groups.Groups[1].Value.ToCharArray()[0] < 91 ? true : false;
  29.                 decimal firstLetter = groups.Groups[1].Value.ToCharArray()[0] < 91 ? groups.Groups[1].Value.ToCharArray()[0] - 64 : groups.Groups[1].Value.ToCharArray()[0] - 96;
  30.                 bool isSecondLetterUpper = groups.Groups[3].Value.ToCharArray()[0] < 91 ? true : false;
  31.                 decimal SecondLetter = groups.Groups[3].Value.ToCharArray()[0] < 91 ? groups.Groups[3].Value.ToCharArray()[0] - 64 : groups.Groups[3].Value.ToCharArray()[0] - 96;
  32.                 decimal currentNum = decimal.Parse(groups.Groups[2].Value.ToString());
  33.  
  34.                 if (isFirstLetterUpper)
  35.                 {
  36.                     currentResult = currentNum / firstLetter;
  37.                 }
  38.                 else
  39.                 {
  40.                     currentResult = currentNum * firstLetter;
  41.                 }
  42.  
  43.                 if (isSecondLetterUpper)
  44.                 {
  45.                     currentResult = currentResult - SecondLetter;
  46.                 }
  47.                 else
  48.                 {
  49.                     currentResult = currentResult + SecondLetter;
  50.                 }
  51.  
  52.  
  53.                 result += currentResult;
  54.             }
  55.  
  56.            
  57.  
  58.             Console.WriteLine($"{result:f2}");
  59.         }
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement