Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Globalization;
- using System.Linq;
- using System.Numerics;
- namespace C_
- {
- class Program
- {
- static void Main(string[] args)
- {
- var input = Console.ReadLine().Split(new char[] { ' ','\t'},StringSplitOptions.RemoveEmptyEntries).ToList();
- decimal result = 0;
- for (int i = 0; i < input.Count; i++)
- {
- string currentWord = input[i];
- char firstChar = currentWord[0];
- char lastChar = currentWord[currentWord.Length - 1];
- var number = currentWord.Substring(1,currentWord.Length-2).ToString();
- if (isUpper(firstChar))
- {
- result += decimal.Parse(number) / charPosition(firstChar);
- }
- else
- {
- result += decimal.Parse(number) * charPosition(firstChar);
- }
- if (isUpper(lastChar))
- {
- result -= charPosition(lastChar);
- }
- else
- {
- result += charPosition(lastChar);
- }
- }
- Console.WriteLine($"{result:F2}");
- }
- static bool isUpper (char currentChar)
- {
- int value = (int)currentChar;
- if (value >= 65 && value <=90)
- {
- return true;
- }
- return false;
- }
- static int charPosition (char currentChar)
- {
- char[] alpha = "%ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray();
- int position = 0;
- for (int i = 0; i < alpha.Length; i++)
- {
- if (currentChar.ToString().ToUpper() == alpha[i].ToString())
- {
- position = i;
- break;
- }
- }
- return position;
- }
- }
- }
Add Comment
Please, Sign In to add comment