Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- class BullsAndCows
- {
- static void Main()
- {
- string input = Console.ReadLine();
- byte bulls = byte.Parse(Console.ReadLine());
- byte cows = byte.Parse(Console.ReadLine());
- byte[] secretNum = new byte[input.Length];
- bool consoleEmpty = true;
- for (byte i = 0; i < input.Length; i++)
- {
- secretNum[i] = Convert.ToByte(Convert.ToString(input[i]));
- }
- byte[] givenNum = new byte[4];
- for (byte firstDigit = 1; firstDigit < 10; firstDigit++)
- {
- for (byte secondDigit = 1; secondDigit < 10; secondDigit++)
- {
- for (byte thirdDigit = 1; thirdDigit < 10; thirdDigit++)
- {
- for (byte fourthDigit = 1; fourthDigit < 10; fourthDigit++)
- {
- for (byte i = 0; i < input.Length; i++)
- {
- secretNum[i] = Convert.ToByte(Convert.ToString(input[i]));
- }
- givenNum[0] = firstDigit;
- givenNum[1] = secondDigit;
- givenNum[2] = thirdDigit;
- givenNum[3] = fourthDigit;
- bool bullsMatch = false;
- bool cowsMatch = false;
- byte b = 0;
- byte c = 0;
- for (byte i = 0; i < 4; i++)
- {
- if (givenNum[i] == secretNum[i])
- {
- secretNum[i] = 0;
- givenNum[i] = 0;
- b++;
- }
- }
- for (byte i = 0; i < 4; i++)
- {
- for (byte k = 0; k < 4; k++)
- {
- if (secretNum[i] == givenNum[k] && secretNum[i] != givenNum[i])
- {
- c++;
- }
- }
- }
- if (c == cows)
- {
- cowsMatch = true;
- }
- if (b == bulls)
- {
- bullsMatch = true;
- }
- if (bullsMatch == true && cowsMatch == true)
- {
- givenNum[0] = firstDigit;
- givenNum[1] = secondDigit;
- givenNum[2] = thirdDigit;
- givenNum[3] = fourthDigit;
- consoleEmpty = false;
- for (byte i = 0; i < 4; i++)
- {
- Console.Write(givenNum[i]);
- }
- Console.Write(" ");
- }
- }
- }
- }
- }
- if (consoleEmpty == true)
- {
- Console.WriteLine("No");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement