No Description

Bakhtina Sofya 46fa6a828b 1st commit 9 months ago
.gitignore.txt 20e2c8c0a9 first commit 9 months ago
README.md 46fa6a828b 1st commit 9 months ago

README.md

Задача 1

Console.WriteLine("Введите год рождения: ");
int year = int.Parse(Console.ReadLine());

for (int year1 = 1900; year1 < 2000; year1++)
{
    for (int month = 1; month <= 12; month++)
    {
        for (int day = 1; day <= DateTime.DaysInMonth(year1, month); day++)
        {
            DateTime date = new DateTime(year1, month, day);
            int age = year - year1;
            int sum1 = CalculateSumOfSquares(year1) - (day * day);

            if (sum1 == age)
            {
                Console.WriteLine("Дата рождения по свойству Васи: " + date.ToShortDateString());
            }
        }
    }
}

static int CalculateSumOfSquares(int year)
{
    int sum = 0;
    foreach (char c in year.ToString())
    {
        sum += int.Parse(c.ToString()) * int.Parse(c.ToString());
    }
    return sum;
}

Задача 2

using System;

class Program
{
    static void Main()
    {
        Console.WriteLine("Введите упакованную строку:");
        string packedString = Console.ReadLine();

        string originalString = UnpackString(packedString);
        Console.WriteLine("Исходная строка: " + originalString);
    }

    static string UnpackString(string packedString)
    {
        string originalString = "";
        string countStr = "";

        foreach (char c in packedString)
        {
            if (char.IsDigit(c))
            {
                countStr += c;
            }
            else
            {
                int count = int.Parse(countStr);
                originalString += new string(c, count);
                countStr = "";
            }
        }

        return originalString;
    }
}

Задача 3

Console.WriteLine("Введите четырехзначное число, которое загадал Петя: ");
int secret = Convert.ToInt32(Console.ReadLine());

Console.WriteLine("Введите предложенное Васей четырёхзначное число: ");
int guess = Convert.ToInt32(Console.ReadLine());

int bulls = CountBulls(secret, guess);
int cows = CountCows(secret, guess);

Console.WriteLine($"Быки: {bulls}");
Console.WriteLine($"Коровы: {cows}");

static int CountBulls(int secret, int guess)
{
    return secret.ToString().Zip(guess.ToString(), (s, g) => s == g ? 1 : 0).Sum();
}

static int CountCows(int secret, int guess)
{
    return secret.ToString().Intersect(guess.ToString()).Count() - CountBulls(secret, guess);
}