simonradev

LettersChangeNumbers

Feb 15th, 2017
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.73 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.  
  7. namespace LettersChangeNumbersSecondTry
  8. {
  9.     public  class LettersChangeNumbersSecondTry
  10.     {
  11.         public static void Main()
  12.         {
  13.             string[] inputLine = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  14.  
  15.             decimal totalSum = 0.0m;
  16.             for (int currCombination = 0; currCombination < inputLine.Length; currCombination++)
  17.             {
  18.                 string combination = inputLine[currCombination];
  19.  
  20.                 StringBuilder numberToParse = new StringBuilder();
  21.                 for (int currNum = 1; currNum < combination.Length - 1; currNum++)
  22.                 {
  23.                     numberToParse.Append(combination[currNum]);
  24.                 }
  25.  
  26.                 char firstLetter = combination[0];
  27.                 char lastLetter = combination[combination.Length - 1];
  28.                 decimal number = decimal.Parse(numberToParse.ToString());
  29.  
  30.                 decimal currSum = 0.0m;
  31.  
  32.                 if (char.IsUpper(firstLetter))
  33.                 {
  34.                     currSum = number / (firstLetter - 'A' + 1);
  35.                 }
  36.                 else
  37.                 {
  38.                     currSum = number * (firstLetter - 'a' + 1);
  39.                 }
  40.  
  41.                 if (char.IsUpper(lastLetter))
  42.                 {
  43.                     currSum -= (lastLetter - 'A' + 1);
  44.                 }
  45.                 else
  46.                 {
  47.                     currSum += (lastLetter - 'a' + 1);
  48.                 }
  49.  
  50.                 totalSum += currSum;
  51.             }
  52.  
  53.             Console.WriteLine($"{totalSum:f2}");
  54.         }
  55.     }
  56. }
Add Comment
Please, Sign In to add comment