Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class BullsAndCows
- {
- static void Main()
- {
- int input = int.Parse(Console.ReadLine());
- int bullsCount = int.Parse(Console.ReadLine());
- int cowsCount = int.Parse(Console.ReadLine());
- int result = 0;
- for (int guessNumber = 1111; guessNumber < 10000; guessNumber++)
- {
- int bulls = 0, cows = 0;
- int currentGuessA = guessNumber / 1000 % 10;
- int currentGuessB = guessNumber / 100 % 10;
- int currentGuessC = guessNumber / 10 % 10;
- int currentGuessD = guessNumber / 1 % 10;
- if(currentGuessA == 0 || currentGuessB == 0
- || currentGuessC == 0 || currentGuessD == 0)
- {
- continue;
- }
- int currentSecA = input / 1000 % 10;
- int currentSecB = input / 100 % 10;
- int currentSecC = input / 10 % 10;
- int currentSecD = input / 1 % 10;
- if (currentGuessA == currentSecA)
- {
- currentGuessA = -1;
- currentSecA = -2;
- bulls++;
- }
- if (currentGuessB == currentSecB)
- {
- currentGuessB = -1;
- currentSecB = -2;
- bulls++;
- }
- if (currentGuessC == currentSecC)
- {
- currentGuessC = -1;
- currentSecC = -2;
- bulls++;
- }
- if (currentGuessD == currentSecD)
- {
- currentGuessD = -1;
- currentSecD = -2;
- bulls++;
- }
- if (currentGuessA == currentSecB)
- {
- currentGuessA = -1;
- currentSecB = -2;
- cows++;
- }
- if (currentGuessA == currentSecD)
- {
- currentGuessA = -1;
- currentSecD = -2;
- cows++;
- }
- if (currentGuessA == currentSecC)
- {
- currentGuessA = -1;
- currentSecC = -2;
- cows++;
- }
- if (currentGuessB == currentSecA)
- {
- currentGuessB = -1;
- currentSecA = -2;
- cows++;
- }
- if (currentGuessB == currentSecC)
- {
- currentGuessB = -1;
- currentSecC = -2;
- cows++;
- }
- if (currentGuessB == currentSecD)
- {
- currentGuessB = -1;
- currentSecD = -2;
- cows++;
- }
- if (currentGuessD == currentSecA)
- {
- currentGuessD = -1;
- currentSecA = -2;
- cows++;
- }
- if (currentGuessD == currentSecB)
- {
- currentGuessD = -1;
- currentSecB = -2;
- cows++;
- }
- if (currentGuessD == currentSecC)
- {
- currentGuessB = -1;
- currentSecC = -2;
- cows++;
- }
- if (currentGuessC == currentSecA)
- {
- currentGuessC = -1;
- currentSecA = -2;
- cows++;
- }
- if (currentGuessC == currentSecB)
- {
- currentGuessC = -1;
- currentSecB = -2;
- cows++;
- }
- if (currentGuessC == currentSecD)
- {
- currentGuessC = -1;
- currentSecD = -2;
- cows++;
- }
- if (cows == cowsCount && bulls == bullsCount)
- {
- result = 1;
- Console.Write(guessNumber + " ");
- }
- }
- if (result == 0)
- {
- Console.WriteLine("No");
- }
- Console.WriteLine();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment