Тайлбар байхгүй

mvavilov 2384efe473 Обновить 'readme.md' 1 долоо хоног өмнө
oap_labs e6cfe55aa7 maks 2 долоо хоног өмнө
.gitignore 91dacc4115 maksim 2 долоо хоног өмнө
oap_labs.sln 91dacc4115 maksim 2 долоо хоног өмнө
readme.md 2384efe473 Обновить 'readme.md' 1 долоо хоног өмнө

readme.md

Лабораторная работа "Работа со строковыми переменными."

Задание 1:

using System;

class Program
{
    static void Main()
    {
        string input;
        while ((input = Console.ReadLine()) != "")
        {
            if (IsValidBusNumber(input))
            {
                Console.WriteLine($"{input} - Правильный номер");
            }
            else
            {
                Console.WriteLine($"{input} - Неправильный номер");
            }
        }
    }

    static bool IsValidBusNumber(string number)
    {
        if (number.Length != 6)
            return false;

        string validLetters = "ABCEHKMOPTXY";

        if (!validLetters.Contains(number[0].ToString()))
            return false;

        for (int i = 1; i <= 3; i++)
        {
            if (!char.IsDigit(number[i]))
                return false;
        }

        if (!validLetters.Contains(number[4].ToString()) || !validLetters.Contains(number[5].ToString()))
            return false;

        return true;
    }
}
X324XX
X324XX - Правильный номер

Задание 2:

using System;
using System.Text;

class Program
{
    static void Main()
    {
        string binarySequence = Console.ReadLine();
        string compressedSequence = CompressBinarySequence(binarySequence);
        Console.WriteLine(compressedSequence);
    }

    static string CompressBinarySequence(string sequence)
    {
        StringBuilder compressed = new StringBuilder();
        int i = 0;
        while (i < sequence.Length)
        {
            if (sequence[i] == '1')
            {
                compressed.Append('a');
                i++;
            }
            else
            {
                int count = 0;
                while (i < sequence.Length && sequence[i] == '0')
                {
                    count++;
                    i++;
                }
                if (i < sequence.Length && sequence[i] == '1')
                {
                    compressed.Append((char)('a' + count));
                    i++;
                }
            }
        }
        return compressed.ToString();
    }
}
0000000001
j

Задание 3:

using System;

class Program
{
    static void Main()
    {
        string sequence = Console.ReadLine();
        int arrowCount = CountArrows(sequence);
        Console.WriteLine(arrowCount);
    }

    static int CountArrows(string sequence)
    {
        int count = 0;
        for (int i = 0; i <= sequence.Length - 5; i++)
        {
            string substring = sequence.Substring(i, 5);
            if (substring == ">>-->" || substring == "<--<<")
            {
                count++;
            }
        }
        return count;
    }
}
<--<<<--<<<
2

Задание 4:

using System;

class Program
{
    static void Main()
    {
        string number = Console.ReadLine();
        int result = CalculateDestinyNumber(number);
        Console.WriteLine(result);
    }

    static int CalculateDestinyNumber(string number)
    {
        while (number.Length > 1)
        {
            int sum = 0;
            foreach (char c in number)
            {
                sum += int.Parse(c.ToString());
            }
            number = sum.ToString();
        }
        return int.Parse(number);
    }
}
77
5

Задание 5:

using System;
using System.Linq;

class Program
{
    static void Main()
    {
        string[] words = Console.ReadLine().Split(' ');
        string word1 = words[0].ToLower();
        string word2 = words[1].ToLower();

        if (AreAnagrams(word1, word2))
        {
            Console.WriteLine("Имя можно получить");
        }
        else
        {
            Console.WriteLine("Имя нельзя получить");
        }
    }

    static bool AreAnagrams(string word1, string word2)
    {
        if (word1.Length != word2.Length)
            return false;

        return string.Concat(word1.OrderBy(c => c)) == string.Concat(word2.OrderBy(c => c));
    }
}
Владимир Стасик
Имя нельзя получить