01. Warrior's Quest-Programming Fundamentals Final Exam Retake - 13 December 2019
https://pastebin.com/LcBBYaQK-Това е моето решение, дава 70/100 . Някой може ли да ми каже къде греша ?
https://pastebin.com/LcBBYaQK-Това е моето решение, дава 70/100 . Някой може ли да ми каже къде греша ?
Може ли да дадеш линк към условието?
2 Problems:
Line 26-34: Stringbuilder needs to be used and only the given letter needs to be replaced. Using skill.Replace will manipulate ALL occurrences of the given letter, but the assignment states only one letter.
Line 62-64: After the "Target" command, if there is no second valid command ("Change", "Remove"), again "Command doesn't exist!" needs to be printed.
New code with 100%:
using System;
using System.Text;
class Program
{
static void Main()
{
string skill = Console.ReadLine();
string input;
while ((input = Console.ReadLine()) != "For Azeroth")
{
string[] inputArgs = input.Split(" ", StringSplitOptions.RemoveEmptyEntries);
string command = inputArgs[0];
switch (command)
{
case "GladiatorStance":
skill = skill.ToUpper();
Console.WriteLine(skill);
break;
case "DefensiveStance":
skill = skill.ToLower();
Console.WriteLine(skill);
break;
case "Dispel":
int index = int.Parse(inputArgs[1]);
char letter = char.Parse(inputArgs[2]);
if (index >= 0 && index < skill.Length)
{
StringBuilder sb = new StringBuilder(skill);
sb[index] = letter;
skill = sb.ToString();
Console.WriteLine("Success!");
}
else
{
Console.WriteLine("Dispel too weak.");
}
break;
case "Target":
string subCommand = inputArgs[1];
switch (subCommand)
{
case "Change":
string subString = inputArgs[2];
string secondSubstring = inputArgs[3];
if (skill.Contains(subString))
{
skill = skill.Replace(subString, secondSubstring);
Console.WriteLine(skill);
}
break;
case "Remove":
subString = inputArgs[2];
if (skill.Contains(subString))
{
index = skill.IndexOf(subString);
skill = skill.Remove(index, subString.Length);
Console.WriteLine(skill);
}
break;
default:
Console.WriteLine("Command doesn't exist!");
break;
}
break;
default:
Console.WriteLine("Command doesn't exist!");
break;
}
}
}
}