Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Text.RegularExpressions;
- namespace ExamPreparation
- {
- public sealed class Preparation
- {
- public static void Main()
- {
- string[] tokens = Console.ReadLine().Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
- double totalSum = 0;
- string pattern = @"([a-zA-z])(\d+)([a-zA-Z])";
- foreach (var token in tokens)
- {
- Match match = Regex.Match(token, pattern);
- char letterBefore = match.Groups[1].Value[0];
- double number = double.Parse(match.Groups[2].Value);
- char letterAfter = match.Groups[3].Value[0];
- if (char.IsLower(letterBefore))
- {
- number *= (letterBefore - 96);
- }
- else
- {
- number /= (letterBefore - 64);
- }
- if (char.IsLower(letterAfter))
- {
- number += (letterAfter - 96);
- }
- else
- {
- number -= (letterAfter - 64);
- }
- totalSum += number;
- }
- Console.WriteLine($"{totalSum:F2}");
- }
- }
- }
Add Comment
Please, Sign In to add comment