08. Letters Change Numbers - Text Processing - Exercise (Runtime Error)
Здравейте, колеги!
Опитвам се да реша посочената в заглавието задача, но ми дава Runtime Error на 5-тия тест. Не мога, и не мога да разбера защо.
Judge линк: https://judge.softuni.bg/Contests/Compete/Index/1217#7
Това е кодът ми: (https://judge.softuni.bg/Contests/Submissions/View/18444151)
using System;
using System.Collections.Generic;
namespace _08.LettersChangeNumbers
{
class Program
{
static void Main(string[] args)
{
string[] inputs = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries);
Dictionary<string, double> dic = new Dictionary<string, double>();
for (int i = 0; i < inputs.Length; i++)
{
string text = inputs[i];
char firstLetter = text[0];
char lastLetter = text[text.Length - 1];
double number = int.Parse(text.Substring(1, text.Length - 2)) * 1.0;
if (char.IsUpper(firstLetter))
{
number /= (firstLetter - 64) * 1.0;
}
else if (char.IsLower(firstLetter))
{
number *= (char.ToUpper(firstLetter) - 64) * 1.0;
}
if (char.IsUpper(lastLetter))
{
number -= (lastLetter - 64) * 1.0;
}
else if (char.IsLower(lastLetter))
{
number += (char.ToUpper(lastLetter) - 64) * 1.0;
}
dic.Add(text, number);
}
double sum = 0.0;
foreach (var item in dic)
{
sum += item.Value;
}
Console.WriteLine($"{sum:F2}");
}
}
}
Благодаря предварително за помощта.
Много Ви благодаря. Не се бях замислила за ключовете в Dictionary.
I don't know what to say really, what you share is so good and useful for the community, I feel that it makes our community much more developed, thanks. fireboy and watergirl