-
Notifications
You must be signed in to change notification settings - Fork 155
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
ViktorKiselev98
wants to merge
3
commits into
urfu-2015:master
Choose a base branch
from
ViktorKiselev98:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+526
−194
Open
Киселев Виктор #153
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
// ============================================================================ 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; | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Отличная реализация!