mirror of
https://gitflic.ru/project/w0lf/bulls-and-cows-cpp.git
synced 2026-03-29 00:12:46 +03:00
43 lines
681 B
C++
43 lines
681 B
C++
// Bulls and Cows the game
|
|
// CStep.cpp
|
|
//
|
|
#include "CStep.h"
|
|
|
|
void CStep::StoreStepNumber(std::vector<int>& digits)
|
|
{
|
|
m_uStepNumber = digits;
|
|
}
|
|
|
|
void CStep::CheckForAnimals(const int* digits, int size)
|
|
{
|
|
int b = 0, c = 0;
|
|
|
|
for (size_t i = 0; i < size; i++) // m_uGuessedNumber
|
|
{
|
|
for (size_t j = 0; j < size; j++) // m_uStepNumber
|
|
{
|
|
if ((m_uStepNumber[i] == digits[j]) && (i == j))
|
|
{
|
|
b++;
|
|
}
|
|
else if (m_uStepNumber[i] == digits[j])
|
|
{
|
|
c++;
|
|
}
|
|
|
|
}
|
|
}
|
|
m_uStepAnimals.first = b;
|
|
m_uStepAnimals.second = c;
|
|
}
|
|
|
|
std::vector<int> CStep::GetStepNumber()
|
|
{
|
|
return m_uStepNumber;
|
|
}
|
|
|
|
std::pair<int, int> CStep::GetStepAnimals()
|
|
{
|
|
return m_uStepAnimals;
|
|
}
|