Advertisement
Guest User

Untitled

a guest
May 10th, 2015
418
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.33 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5. using System.Threading.Tasks;
  6.  
  7. namespace LettersNumbers_7
  8. {
  9.     class LettersNumbers_7
  10.     {
  11.         static decimal result = 0;
  12.  
  13.         static void CalcResult(char first,char last,int num)
  14.         {          
  15.             if (Char.IsUpper(first))
  16.             {
  17.                 result += num / (decimal)(first - 'A' + 1);
  18.             }
  19.             else if (Char.IsLower(first))
  20.             {
  21.                 result += num * (decimal)(first - 'a' + 1);
  22.             }
  23.  
  24.             if (Char.IsUpper(last))
  25.             {
  26.                 result -= (decimal)(last - 'A' + 1);
  27.             }
  28.             else if (Char.IsLower(last))
  29.             {
  30.                 result += (decimal)(last - 'a' + 1);
  31.             }
  32.         }
  33.         static void Main(string[] args)
  34.         {
  35.             string[] input = Console.ReadLine().Split(new[]{' '},StringSplitOptions.RemoveEmptyEntries);
  36.             foreach (var word in input)
  37.             {
  38.                 char first = word.First();
  39.                 char last = word.Last();
  40.                 int number = int.Parse(Regex.Match(word, @"\d+").Value);
  41.  
  42.                 CalcResult(first, last, number);
  43.             }
  44.             Console.WriteLine("{0:F2}",result);
  45.         }
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement