08. Letters Change Numbers*- (Text Processing - Exercise) 40/100
I need some help for this exercise. I will apreciate it a lot if somebody takes out of their time to check my rounded method.
With this input "A12b s17G" my output is correct- "330.00" and with this input "a1A" my output is correct too, but with " P34562Z q2576f H456z" my output is "46015.00", not "46015.13".
https://softuni.bg/trainings/resources/officedocument/49591/text-processing-exercise-csharp-fundamentals-may-2020/2830
https://judge.softuni.bg/Contests/Compete/Index/1217#7
using System;
using System.Text;
using System.Linq;
namespace text
{
class MainClass
{
public static void Main(string[] args)
{
string[] inputArray = Console.ReadLine().Split(" ",StringSplitOptions.RemoveEmptyEntries);
string alphabetUpperCase = "ABCDEFGHIGKLMNOPQRSTUVWXYZ";
string alphabetLowerCase = "abcdefghigklmnopqrstuvwxyz";
int allSum = 0;
foreach (var text in inputArray)
{
int firstCurrentSum = 0;
int lastCurrentSum = 0;
char firstLetter = text[0];
char lastLetter = text[text.Length - 1];
int numberLength = text.Length - 2;
string numberLikeString = text.Substring(1, numberLength);
int number = int.Parse(numberLikeString);
if (alphabetUpperCase.Contains(firstLetter))
{
int firstLetterPositionInAlphabet = alphabetUpperCase.IndexOf(firstLetter)+1;
firstCurrentSum=number / firstLetterPositionInAlphabet;
}
else if (alphabetLowerCase.Contains(firstLetter))
{
int firstLetterPositionInAlphabet = alphabetLowerCase.IndexOf(firstLetter)+1;
firstCurrentSum =number * firstLetterPositionInAlphabet;
}
if (alphabetUpperCase.Contains(lastLetter))
{
int lastLetterPositionInAlphabet = alphabetUpperCase.IndexOf(lastLetter)+1;
lastCurrentSum = firstCurrentSum - lastLetterPositionInAlphabet;
}
else if (alphabetLowerCase.Contains(lastLetter))
{
int lastLetterPositionInAlphabet = alphabetLowerCase.IndexOf(lastLetter)+1;
lastCurrentSum =firstCurrentSum + lastLetterPositionInAlphabet;
}
allSum += lastCurrentSum;
}
Console.WriteLine($"{allSum:f2}");
}
}
}
Hi Axiomatik,
thanks for your code. As far as I remember about MidpointRounding.AwayFromZero from one lecture in Basic this rounding is used in some bank operations.. and for this letter exercise .
On my Monodevelop this rounding isn't working and my code is still 40/100. It wouldn't matter and I can go to another exercise, because acording to you my code seems Ok.
Thanks a lot for all your help!
Best regards!