Advertisement
Spocoman

08. Letters Change Numbers

Apr 16th, 2023
906
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.91 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. using System.Text;
  5.  
  6. namespace LettersChangeNumbers
  7. {
  8.  
  9.     class Program
  10.     {
  11.         static void Main()
  12.         {
  13.             string[] tokens = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries);
  14.             double totalSum = 0;
  15.  
  16.             for (int i = 0; i < tokens.Length; i++)
  17.             {
  18.                 char firstLetter = tokens[i][0];
  19.                 char secondLetter = tokens[i][^1];
  20.                 double number = int.Parse(tokens[i].Substring(1, tokens[i].Length - 2));
  21.  
  22.                 _ = char.IsUpper(firstLetter) ? number /= firstLetter - 64 : number *= firstLetter - 96;
  23.                 _ = char.IsUpper(secondLetter) ? number -= secondLetter - 64 : number += secondLetter - 96;
  24.  
  25.                 totalSum += number;
  26.             }
  27.  
  28.             Console.WriteLine($"{totalSum:f2}");
  29.         }
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement