Nincs leírás

ebakhtin 7d265d07d0 Загрузить файлы '' 7 hónapja
Program.cs 7d265d07d0 Загрузить файлы '' 7 hónapja
lab4.csproj 7d265d07d0 Загрузить файлы '' 7 hónapja
lab4.sln 7d265d07d0 Загрузить файлы '' 7 hónapja
readme.md 7d265d07d0 Загрузить файлы '' 7 hónapja

readme.md

Задача 1

Решение:

var symbols = "ABCEHKMOPTXY";
var digits = "0123456789";
while (true)
{
    Console.Write("Номер: ");
    var number = Console.ReadLine();
    if (number.Length == 6)
    {
        for (int i = 0; i < number.Length; i++)
        {
            if (i > 0 && i < 4)
            {
                if (!digits.Contains(number[i]))
                {
                    Console.WriteLine("bad digit");
                    break;
                }
            }

            else if (!symbols.Contains(number[i]))
            {
                Console.WriteLine("bad symbol");
                break;
            }
        }
    }
    else if (number.Length < 6 | number.Length > 6)
    {
        Console.WriteLine("bad length");
    }
}

Результат:

Номер: A123XT
Номер: B824AC
Номер: A82ABX 
bad digit

Задача 2

Решение:

string[] binary = new string[]
{
    "a", "a", "b", "c", "d", "e", "f", "g",
    "h", "i", "j", "k", "l", "m", "n", "o", 
    "p", "q", "r", "s", "t", "u", "v", "w", 
    "x", "y", "z"
};
while (true)
{
    int a = 0;
    string otvet = String.Empty;
    Console.Write("binary code: ");
    string code = Console.ReadLine();
    for (int i = 0; i < code.Length; i++)
    {
        if (code[i] == '0')
        {
            a++;
        }
        else if (code[i] == '1')
        {
            a++;
            Console.Write(binary[a]);
            a = 0;
        }
        else
        {
            Console.WriteLine();
            Console.WriteLine("bad symbol");
            break;
        }

        if (i == (int)code.Length-1)
        {
            Console.WriteLine();
        }
    }
}

Результат:

binary code: 101001
abc          
binary code: 00000100000001110001
fhaad        
binary code: 

Задача 3

Решение:

while (true)
{
    int i = 0;
    int arrows1 = 0;
    int arrows2 = 0;
    Console.Write("arrows: ");
    string str = Console.ReadLine();
    int count = str.Length;
    while (count != 0)
    {
        if (str.IndexOf("<--<<",i,count) != -1)
        {
            i = str.IndexOf("<--<<", i, count) + 5;
            count = str.Length - i;
            arrows1++;
        }
        else
        {
            break;
        }
    }

    count = str.Length;
    i = 0;
    while (count != 0)
    {
        if (str.IndexOf(">>-->",i,count) != -1)
        {
            i = str.IndexOf(">>-->", i, count) + 5;
            count = str.Length - i;
            arrows2++;
        }
        else
        {
            break;
        }
    }

    Console.WriteLine(arrows1 + arrows2);
}

Результат:

arrows: <--<<<--<<>>--><--<<
4       

Задача 4

Решение:

int a = 0, count = 0;
Console.Write("Секунды: ");
long seconds = long.Parse(Console.ReadLine());

while (seconds > 0)
{
    a += ((int)seconds % 10);
    seconds /= 10;
}
count++;
int b = a;
a = 0;

if (b < 10)
{
    while (b >= 10)
    {
        while (b > 0)
        {
            a += ((int)b % 10);
            b /= 10;
        }

        count++;
        b = a;
        a = 0;
    }
    
    Console.Write($"Число: {b}, итераций: {count}");
}
else
{
    Console.Write($"Число: {a}, итераций: {count}");
}

Результат:

Секунды: 4199999999
Число: 7, итераций: 2

Задача 5

Решение:

while (true)
{
    string str = String.Empty;
    string str2 = String.Empty;

    Console.Write("first name: ");
    string[] string1 = Console.ReadLine().ToLower().Split(' ');
    for (int i = 0; i < string1.Length; i++)
    {
        str = str + string1[i];
    }

    Console.Write("second name: ");
    string[] string2 = Console.ReadLine().ToLower().Split(' ');
    for (int i = 0; i < string2.Length; i++)
    {
        str2 = str2 + string2[i];
    }


    for (int i = 0; i < str2.Length; i++)
    {
        for (int j = 0; j < str2.Length - i - 1; j++)
        {
            if((str2[j]) > (str2[j + 1]))
            {
                string a = str2[j].ToString();
                string b = str2[j + 1].ToString();
                str2 = str2.Remove(j, 1).Insert(j, b);
                str2 = str2.Remove((j + 1), 1).Insert(j + 1, a);
            }
        }
    }

    for (int i = 0; i < str.Length; i++)
    {
        for (int j = 0; j < str.Length - i - 1; j++)
        {
            if((str[j]) > (str[j + 1]))
            {
                string a = str[j].ToString();
                string b = str[j + 1].ToString();
                str = str.Remove(j, 1).Insert(j, b);
                str = str.Remove((j + 1), 1).Insert(j + 1, a);
            }
        }
    }

    if (string.Compare(str2,str) == 0)
    {
        Console.WriteLine("Yes");
    }

    else
    {
        Console.WriteLine("No");
    }
}

Результат:

first name: I Am Lord Voldemort
second name: Tom Marvolo Riddle
Yes         
first name: Egor Bakhtin
second name: Boger Kahtin
Yes