Guest User

09.String and Text Processing Exercise08LettersChangeNumbers

a guest
May 9th, 2018
145
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace _08LettersChangeNumbers
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             string[] input = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries);
  11.             double sum = 0;
  12.             double tempSum = 0;
  13.             for (int i = 0; i < input.Length; i++)
  14.             {
  15.                 char firstLetter = input[i].ElementAt(0);
  16.                 char lastLetter = input[i].ElementAt(input[i].Length - 1);
  17.                 string num = new string(input[i].Skip(1).Take(input[i].Length - 2).ToArray());
  18.                 tempSum = int.Parse(num);
  19.                 if (char.IsUpper(firstLetter))
  20.                 {
  21.                     tempSum /= (firstLetter - 64);
  22.                 }
  23.                 else
  24.                 {
  25.                     tempSum *= (firstLetter - 96);
  26.                 }
  27.                 if (char.IsUpper(lastLetter))
  28.                 {
  29.                     tempSum -= (lastLetter - 64);
  30.                 }
  31.                 else
  32.                 {
  33.                     tempSum += (lastLetter - 96);
  34.                 }
  35.                 sum += tempSum;
  36.             }
  37.             Console.WriteLine($"{sum:f2}");
  38.         }
  39.     }
  40. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×