Advertisement
Guest User

Change Nums

a guest
Feb 21st, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.51 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6. using System.Threading.Tasks;
  7. using System.Numerics;
  8. using System.Globalization;
  9. using System.Net;
  10.  
  11. namespace ConsoleApplication3
  12. {
  13.     class Program
  14.     {
  15.         static double Sum(string n)
  16.         {
  17.             var alphabet = new List<char>{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
  18.                             'v', 'w', 'x', 'y', 'z'};
  19.             char first = n.ToCharArray()[0];
  20.             char second = n.ToCharArray()[n.Length - 1];
  21.             double num = double.Parse(n.Substring(1, n.Length - 2));
  22.            
  23.             if (char.IsUpper(first))
  24.                 num = num / (alphabet.IndexOf(char.ToLower(first)) + 1);
  25.             else
  26.                 num = num * (alphabet.IndexOf(first) + 1);
  27.  
  28.             if(char.IsUpper(second))
  29.                 num = num - (alphabet.IndexOf(char.ToLower(second)) + 1);
  30.             else
  31.                 num = num + (alphabet.IndexOf(second) + 1);
  32.  
  33.             return num;
  34.         }
  35.  
  36.         static void Main(string[] args)
  37.         {
  38.             string[] input = Console.ReadLine().Split(new char[]{' '}, StringSplitOptions.RemoveEmptyEntries).ToArray();
  39.  
  40.             double result = 0;
  41.  
  42.             foreach (string i in input)
  43.             {
  44.                 result += Sum(i);
  45.             }
  46.  
  47.             Console.WriteLine("{0:F2}", result);
  48.         }
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement