1
Console.Write("Введите год: ");
int year21 = int.Parse(Console.ReadLine());
for (int year = 1900; year <= 1999; year++)
{
for (int month = 1; month <= 12; month++)
{
for (int day = 1; day < DateTime.DaysInMonth(year,month); day++)
{
bool a = dob(year21, year, month, day);
if (a == true)
{
Console.WriteLine( new DateTime(year,month,day).ToShortDateString());
}
}
}
}
static bool dob(int year21, int year, int moth, int day)
{
int sq = 0;
foreach (var numb in year.ToString())
{
sq += Convert.ToInt32(numb.ToString()) * Convert.ToInt32(numb.ToString());
}
if (sq - day * day == year21 - year)
{
return true;
}
else
{
return false;
}
}
2
Console.Write("string: ");
string str = Console.ReadLine();
string newstr = "";
int count = 1;
for (int i = 0; i < str.Length; i++)
{
if (i == str.Length - 1 || str[i] != str[i + 1])
{
if (count == 1)
{
newstr += str[i];
count = 1;
}
else
{
newstr += count.ToString() + str[i];
count = 1;
}
}
else
{
count++;
}
}
Console.WriteLine(newstr);
3
Console.Write("Загадайте число: ");
string numbertrue = Console.ReadLine();
Console.Write("Предположите число: ");
string numbertry = Console.ReadLine();
Console.WriteLine($"Быков: {bulls(numbertrue,numbertry)}, коров: {cows(numbertrue,numbertry)}");
static int bulls(string str1, string str2)
{
int bulls = 0;
for (int i = 0; i < str1.Length; i++)
{
if (str1[i] == str2[i])
{
bulls++;
}
}
return bulls;
}
static int cows(string str1, string str2)
{
int cows = 0;
for (int i = 0; i < str1.Length; i++)
{
for (int j = 0; j < str2.Length; j++)
{
if (str1 [i] == str2[j])
{
if (i != j)
{
cows++;
}
}
}
}
return cows;
}