Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace _14.Letters_Change_Numbers
- {
- public class LettersChangeNums
- {
- public static void Main()
- {
- string[] line = Console.ReadLine()
- .Split(new[] {' ', '\t', '\n', '\r'}, StringSplitOptions.RemoveEmptyEntries);
- int position = 0;
- decimal sum = 0M;
- decimal total = 0M;
- foreach (var str in line)
- {
- char firstLetter = str[0];
- char secondLetter = str[str.Length - 1];
- decimal num = decimal.Parse(str.Substring(1, str.Length - 2));
- if (Char.IsUpper(firstLetter))
- {
- position = (int)firstLetter - (int)'A' + 1;
- sum = num / position;
- }
- if (Char.IsLower(firstLetter))
- {
- position = (int)firstLetter - (int)'a' + 1;
- sum = num * position;
- }
- if(Char.IsUpper(secondLetter))
- {
- position = (int)secondLetter - (int)'A' + 1;
- sum -= position;
- }
- if (Char.IsLower(secondLetter))
- {
- position = (int)secondLetter - (int)'a' + 1;
- sum += position;
- }
- total += sum;
- sum = 0;
- }
- Console.WriteLine("{0:f2}", total);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment