Loading...

Във форума е въведено ограничение, което позволява на потребителите единствено да разглеждат публикуваните въпроси.

VelislavAngelov avatar VelislavAngelov 0 Точки

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();
            }
        }
    }
}

 

Тагове:
0
Module: C# Advanced
swade avatar swade 1 Точки

 string word = userName.Substring(startIndex, (endIndex - startIndex) + 1);
                    Console.WriteLine(string.Join("", word.Reverse()));

0
VelislavAngelov avatar VelislavAngelov 0 Точки

не се променя judge дава 90/100.

 

0
swade avatar swade 1 Точки

https://pastebin.com/QyhHXR3v

0
Можем ли да използваме бисквитки?
Ние използваме бисквитки и подобни технологии, за да предоставим нашите услуги. Можете да се съгласите с всички или част от тях.
Назад
Функционални
Използваме бисквитки и подобни технологии, за да предоставим нашите услуги. Използваме „сесийни“ бисквитки, за да Ви идентифицираме временно. Те се пазят само по време на активната употреба на услугите ни. След излизане от приложението, затваряне на браузъра или мобилното устройство, данните се трият. Използваме бисквитки, за да предоставим опцията „Запомни Ме“, която Ви позволява да използвате нашите услуги без да предоставяте потребителско име и парола. Допълнително е възможно да използваме бисквитки за да съхраняваме различни малки настройки, като избор на езика, позиции на менюта и персонализирано съдържание. Използваме бисквитки и за измерване на маркетинговите ни усилия.
Рекламни
Използваме бисквитки, за да измерваме маркетинг ефективността ни, броене на посещения, както и за проследяването дали дадено електронно писмо е било отворено.