Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Киселев Виктор #153

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
269 changes: 266 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,266 @@
<html>
<!-- Ваш замечательный код -->
</html>


#include <iostream>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <iterator>
//============================================================================================= 1 задание =========================================================
using namespace std;
class ArrayInt
{
private:
int m_length;
int* m_data;

public:
ArrayInt() : m_length(0), m_data(nullptr)
{

}

ArrayInt(int length) : m_length(length)
{
assert(length >= 0);
if (length > 0)
m_data = new int[length];
else
m_data = nullptr;
}

~ArrayInt()
{
delete[] m_data;
}

void erase()
{
delete[] m_data;

m_data = nullptr;
m_length = 0;
}

int& operator[](int index)
{
assert(index >= 0 && index < m_length);
return m_data[index];
}


void reallocate(int newLength)
{

erase();


if (newLength <= 0)
return;


m_data = new int[newLength];
m_length = newLength;
}


void resize(int newLength)
{

if (newLength == m_length)
return;


if (newLength <= 0)
{
erase();
return;
}


int* data = new int[newLength];


if (m_length > 0)
{
int elementsToCopy = (newLength > m_length) ? m_length : newLength;


for (int index = 0; index < elementsToCopy; ++index)
data[index] = m_data[index];
}


delete[] m_data;


m_data = data;
m_length = newLength;
}

void insertBefore(int value, int index)
{

assert(index >= 0 && index <= m_length);

int* data = new int[m_length + 1];


for (int before = 0; before < index; ++before)
data[before] = m_data[before];


data[index] = value;

for (int after = index; after < m_length; ++after)
data[after + 1] = m_data[after];


delete[] m_data;
m_data = data;
++m_length;
}

void remove(int index)
{

assert(index >= 0 && index < m_length);


if (m_length == 1)
{
erase();
return;
}


int* data = new int[m_length - 1];


for (int before = 0; before < index; ++before)
data[before] = m_data[before];


for (int after = index + 1; after < m_length; ++after)
data[after - 1] = m_data[after];

delete[] m_data;
m_data = data;
--m_length;
}

void insertAtBeginning(int value)
{
insertBefore(value, 0);

}
void insertAtEnd(int value)
{
insertBefore(value, m_length);

}

int getLength()
{
return m_length;
}
};
//============================================================================ 2 задание ==========================================================================

int main()
{

std::vector<int> v = { 1,1,2,5 };
std::set<int> s(v.begin(), v.end());
std::cout << s.size() << std::endl;
Comment on lines +174 to +176
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Отличная реализация!

}
// ============================================================================ 3 задание ===============================================================================
class Hand
{
public:
Hand();

virtual ~Hand();


void Add(Card* pCard);

void Clear();

int GetTotal() const;

protected:
vector<Card*> m_Cards;
};

Hand::Hand()
{
m_Cards.reserve(7);
}

Hand::~Hand()
{
Clear();
}

void Hand::Add(Card* pCard)
{
m_Cards.push_back(pCard);
}

void Hand::Clear()
{

vector<Card*>::iterator iter;
for (iter = m_Cards.begin(); iter != m_Cards.end(); ++iter)
{
delete* iter;
*iter = 0;
}

m_Cards.clear();
}

int Hand::GetTotal() const
{

if (m_Cards.empty())
{
return 0;
}


if (m_Cards[0]->GetValue() == 0)
{
return 0;
}


int total = 0;
vector<Card*>::const_iterator iter;
for (iter = m_Cards.begin(); iter != m_Cards.end(); ++iter)
{
total += (*iter)->GetValue();
}


bool containsAce = false;
for (iter = m_Cards.begin(); iter != m_Cards.end(); ++iter)
{
if ((*iter)->GetValue() == Card::ACE)
{
containsAce = true;
}
}


if (containsAce && total <= 11)
{

total += 10;
}

return total;
}