Website Summary Files Commits Branches @commit @diff @stats
path: root / Sem. 7 / BullsAndColls.cpp
diff options
context:
space:
mode:
Commit7881119e0914b9207568918fcf868eea84ef3d78 (patch)
Author
 Angeld55 <angel_dimitriev@abv.bg>
2020-11-28 01:45:44 +0200
Committer
 Angeld55 <angel_dimitriev@abv.bg>
2020-11-28 01:45:44 +0200
Filesab70701506971ec44b9aab9ba00ad9525b8da0e5 /Sem. 7/BullsAndColls.cpp
Introduction_to_programming_FMI-7881119e0914b9207568918fcf868eea84ef3d78.tar
Introduction_to_programming_FMI-7881119e0914b9207568918fcf868eea84ef3d78.tar.gz
Introduction_to_programming_FMI-7881119e0914b9207568918fcf868eea84ef3d78.zip
Parente5646c51794632f5816c00f4d1e7933ea7dcbbc0 (diff)
sem 8
1 files changed, 0 insertions, 100 deletions
-rw-r--r--Sem. 7/BullsAndColls.cpp100
diff --git a/Sem. 7/BullsAndColls.cpp b/Sem. 7/BullsAndColls.cpp
deleted file mode 100644
index 5b5a54e..0000000
--- a/Sem. 7/BullsAndColls.cpp
+++ /dev/null
@@ -1,100 +0,0 @@
-#include <iostream>
-#include <stdlib.h>
-using namespace std;
-
-
-//Играта бикове и крави.
-// Комп. генерира случайно число ви интервала [1000...9999].
-// Ние трябва да го познаем.
-
-
-// 4278 - 1 бик, 1 крава (бик - число и позицията), (крава - числото , но и позицията)
-// Познавам числото, когато имам 4 бика
-
-bool hasDuplicateDigits(int n) ///1343
-{
- const int DIGITCOUNT = 10;
- bool found[DIGITCOUNT];
- for (int i = 0; i < DIGITCOUNT; i++)
- found[i] = false;
- while (n != 0)
- {
- int lastDigit = n % 10;
- if (found[lastDigit] == true)
- return true;
- else
- found[lastDigit] = true;
- n /= 10;
- }
- return false;
-}
-
-void convertNumberToArr(int n, int arr[])
-{
-
- for (int i = 3; i >= 0; i--)
- {
- arr[i] = n % 10;
- n /= 10;
- }
-
-}
-int countBulls(int myNumber[], int compNumber[])
-{
- int bullsCount = 0;
- for (int i = 0; i <= 3; i++)
- {
- if (myNumber[i] == compNumber[i])
- bullsCount++;
- }
- return bullsCount;
-}
-int countCows(int myNumber[], int compNumber[])
-{
- int cowsCount = 0;
-
- for (int i = 0; i <= 3; i++)
- {
- int myDigit = myNumber[i];
- for (int j = 0; j <= 3; j++)
- {
- if (j == i) // за да не броим биковете
- continue;
- if (myDigit == compNumber[j])
- cowsCount++;
- }
- }
- return cowsCount;
-}
-int main()
-{
- int numberToGuess;
- do
- {
- numberToGuess = 1000 + rand() % 9000; // [1000..9999]
- }
- while (hasDuplicateDigits(numberToGuess));
-
- cout << "Computer has picked a number! Try to guess it!" <<endl;
- int numberToGuessArr[4];
-
- convertNumberToArr(numberToGuess, numberToGuessArr);
-
- int bullsCount = 0, cowsCount = 0;
- do
- {
- int myNumber;
- cin >> myNumber;
- int myNumberArr[4];
- convertNumberToArr(myNumber, myNumberArr);
-
- bullsCount = countBulls(myNumberArr, numberToGuessArr);
- cowsCount = countCows(myNumberArr, numberToGuessArr);
-
- cout << "Bulls: " << bullsCount << " Cows:" << cowsCount << endl;
-
-
- } while (bullsCount != 4);
-
- cout << "Success!" << endl;
-} \ No newline at end of file