Advertisement
Guest User

Untitled

a guest
May 26th, 2015
1,018
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.85 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text.RegularExpressions;
  4.  
  5. class LettersChangeNumbers
  6. {
  7.     static void Main()
  8.     {
  9.         string input = Console.ReadLine();
  10.         string[] text = input.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  11.         List<string> textList = new List<string>();
  12.         List<int> onlyNumbers = new List<int>();
  13.  
  14.         for(int i = 0; i < text.Length; i++)
  15.         {
  16.             textList.Add(text[i]);
  17.         }
  18.  
  19.  
  20.         string pattern = @"[0-9]+";
  21.         Regex rgx = new Regex(pattern);
  22.         for (int i = 0; i < textList.Count; i++)
  23.         {
  24.             Match mth = rgx.Match(textList[i]);
  25.             string a = Convert.ToString(mth.Groups[0]);
  26.             int number = int.Parse(a);
  27.             onlyNumbers.Add(number);
  28.         }
  29.  
  30.         double sum = 0;
  31.         double sum1 = 0;
  32.        
  33.         for (int i = 0; i < text.Length; i++)
  34.         {
  35.                 if (char.IsUpper(text[i][0]))
  36.                 {
  37.                     double convert = (double)Convert.ToChar(text[i][0]);
  38.                     sum1 = onlyNumbers[i] / (convert - 64.0);
  39.                 }
  40.                 else
  41.                 {
  42.                     double convert = (double)Convert.ToChar(text[i][0]);
  43.                     sum1 = onlyNumbers[i] * (convert - 96.0);
  44.                 }
  45.                 if (char.IsUpper(text[i][text[i].Length - 1]))
  46.                 {
  47.                     double convert = (double)Convert.ToChar(text[i][text[i].Length - 1]);
  48.                     sum += sum1 - (convert - 64.0);
  49.                 }
  50.                 else
  51.                 {
  52.                     double convert = (double)Convert.ToChar(text[i][text[i].Length - 1]);
  53.                     sum += sum1 + (convert - 96.0);
  54.                 }
  55.         }
  56.  
  57.         Console.WriteLine("{0:F2}", sum);
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement