Programming Fundamentals Final Exam Retake - 9 August 2019 задача Username
judge ми дава 90/100
Ето решениетто ми:
using System;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections.Generic;
namespace Final_Exam_Retake___9_August_2019_Username
{
class Program
{
static void Main(string[] args)
{
string userName = Console.ReadLine();
string input = Console.ReadLine();
while (input!= "Sign up")
{
string[] commands = input.Split(" ");
string command = commands[0];
if(command== "Case")
{
string casees = commands[1];
if(casees== "lower")
{
userName = userName.ToLower();
Console.WriteLine(userName);
}
else
{
userName = userName.ToUpper();
Console.WriteLine(userName);
}
}
else if(command== "Reverse")
{
int startIndex = int.Parse(commands[1]);
int endIndex = int.Parse(commands[2]);
if (startIndex >= 0 && startIndex < userName.Length&& endIndex > startIndex && endIndex < userName.Length)
{
int startIndexes = userName.IndexOf(userName[startIndex]);
int endIndexes = userName.LastIndexOf(userName[endIndex]);
int length = endIndexes - startIndexes + 1;
string word = userName.Substring(startIndexes,length);
Console.WriteLine(string.Join("", word.Reverse()));
}
}
else if(command== "Cut")
{
string word = commands[1];
if (userName.Contains(word))
{
userName = userName.Remove(userName.IndexOf(word), word.Length);
Console.WriteLine(userName);
}
else
{
Console.WriteLine($"The word {userName} doesn't contain {word}.");
}
}
else if(command== "Check")
{
string word = commands[1];
if (userName.Contains(word))
{
Console.WriteLine("Valid");
}
else
{
Console.WriteLine($"Your username must contain {word}.");
}
}
else if(command== "Replace")
{
string replacement = commands[1];
userName = userName.Replace(replacement, "*");
Console.WriteLine(userName);
}
input = Console.ReadLine();
}
}
}
}
не се променя judge дава 90/100.
https://pastebin.com/QyhHXR3v
Благодаря