Advertisement
Guest User

Letters Change Numbers

a guest
Sep 25th, 2015
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.15 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. class LettersChangeNumbers
  5. {
  6.     static void Main()
  7.     {
  8.         var line = Console.ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
  9.  
  10.         double result = 0;
  11.         foreach (var str in line)
  12.         {
  13.             var firstLetter = str.First();
  14.             var lastLetter = str.Last();
  15.             var number = double.Parse(str.Substring(1, str.Length - 2));
  16.  
  17.             number = ApplyFirstLetterCalculations(firstLetter, number);
  18.             number = ApplySecondLetterCalculations(lastLetter, number);
  19.  
  20.             result += number;
  21.         }
  22.  
  23.         Console.WriteLine("{0:F2}", result);
  24.     }
  25.  
  26.     private static double ApplySecondLetterCalculations(char lastLetter, double number)
  27.     {
  28.         number = char.IsUpper(lastLetter) ? number - (lastLetter - 'A' + 1) : number + (lastLetter - 'a' + 1);
  29.         return number;
  30.     }
  31.  
  32.     private static double ApplyFirstLetterCalculations(char firstLetter, double number)
  33.     {
  34.         number = char.IsUpper(firstLetter) ? number / (firstLetter - 'A' + 1) : number * (firstLetter - 'a' + 1);
  35.         return number;
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement