123456789101112131415161718 |
- //3
- Console.WriteLine("Введите цифры: ");
- int secret = Convert.ToInt16(Console.ReadLine());
- int guess = Convert.ToInt16(Console.ReadLine());
- Console.WriteLine($"Быки: {CountBulls(secret, guess)}");
- Console.WriteLine($"Коровы: {CountCows(secret, guess)}");
- 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);
- }
|