task3.cs 556 B

123456789101112131415161718
  1. //3
  2. Console.WriteLine("Введите цифры: ");
  3. int secret = Convert.ToInt16(Console.ReadLine());
  4. int guess = Convert.ToInt16(Console.ReadLine());
  5. Console.WriteLine($"Быки: {CountBulls(secret, guess)}");
  6. Console.WriteLine($"Коровы: {CountCows(secret, guess)}");
  7. static int CountBulls(int secret, int guess)
  8. {
  9. return secret.ToString().Zip(guess.ToString(), (s, g) => s == g ? 1 : 0).Sum();
  10. }
  11. static int CountCows(int secret, int guess)
  12. {
  13. return secret.ToString().Intersect(guess.ToString()).Count() - CountBulls(secret, guess);
  14. }