Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class Program
- {
- static void Main()
- {
- string secret = Console.ReadLine();
- int bulls = int.Parse(Console.ReadLine());
- int cows = int.Parse(Console.ReadLine());
- int answers = 0;
- for (int i1 = 1; i1 <= 9; i1++)
- {
- for (int i2 = 1; i2 <= 9; i2++)
- {
- for (int i3 = 1; i3 <= 9; i3++)
- {
- for (int i4 = 1; i4 <= 9; i4++)
- {
- int guess = i1 * 1000 + i2 * 100 + i3 * 10 + i4;
- string guessStr = guess.ToString();
- int guessBulls = 0;
- int guessCows = 0;
- for (int digit = 0; digit < 4; digit++)
- {
- char currentSecret = secret[digit];
- bool isBull = false;
- if (currentSecret == guessStr[digit])
- {
- isBull = true;
- guessBulls += 1;
- }
- if (isBull)
- continue;
- for (int otherDigit = 0; otherDigit < 4; otherDigit++)
- {
- if (otherDigit == digit)
- continue;
- if (currentSecret == guessStr[otherDigit] &&
- guessStr[otherDigit] != secret[otherDigit])
- {
- guessCows += 1;
- break;
- }
- }
- }
- if (guessCows == cows && guessBulls == bulls)
- {
- Console.Write(guess + " ");
- answers += 1;
- }
- }
- }
- }
- }
- if (answers == 0)
- Console.WriteLine("No");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment