Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 8 additions & 3 deletions 1.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
// Разверните строку. Указатель reverse_string должен
// указывать на развернутую строку.

char* string = "The string!";
char* string = The string!;

Choose a reason for hiding this comment

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

Погані лапки


int main()
{
char* reverse_string;

int sz = strlen(string);
reverse_string= new char[sz+1];
for(int i=0; i<sz;i++)
reverse_string[i]=string[sz-1-i];
reverse_string[sz]='\0';
std::cout << reverse_string;
return 0;
}
}
12 changes: 11 additions & 1 deletion 2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,22 @@ typedef int Matrix[c_kM][c_kM];

int min_from_top_sector(Matrix& m)
{

int temp = m[0][0];
for(int i=0; i<=c_kM/2; i++)
for(int j=i;j<c_kM-i;j++)
if(temp > m[i][j]) temp=m[i][j];
return temp;
}

int _tmain(int argc, _TCHAR* argv[])
{
Matrix matrix;
for(int i=0; i<c_kM; i++)
for(int j=0;j<c_kM;j++)
{
std::cout << std::endl << "m[" <<i+1 <<"]["<<j+1<<"]=";
std::cin >> matrix[i][j];
}

std::cout << min_from_top_sector(matrix) << std::endl;

Expand Down
14 changes: 12 additions & 2 deletions 3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,20 @@ struct List
// It should return pointer to the added List object.
List* Add(List* l, int value)
{

List* obj = new List;
obj->value = value;
obj->next=NULL; //for last element to point NULL
l->next = obj;
return obj;
}

int main(int argc, char* argv[])
{
List myList;
myList->value=1;
List* temp = &myList;
for(int i=2; i <=5;i++)
temp = Add(temp,i);

return 0;
}
}
35 changes: 35 additions & 0 deletions Pacman/Pacman.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#-------------------------------------------------
#
# Project created by QtCreator 2014-06-07T16:25:03
#
#-------------------------------------------------

QT += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = Pacman
TEMPLATE = app


SOURCES += main.cpp\
pacman.cpp \
gamemap.cpp \
creature.cpp \
pacman_creature.cpp \
monster_creature.cpp

HEADERS += pacman.h \
gamemap.h \
creature.h \
pacman_creature.h \
monster_creature.h \
ThreadPool.h

FORMS += pacman.ui

RESOURCES += \
Source_files.qrc
CONFIG += c++11
OTHER_FILES +=

251 changes: 251 additions & 0 deletions Pacman/Pacman.pro.user

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions Pacman/Source_files.qrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<RCC>
<qresource prefix="/">
<file>finish.png</file>
<file>gold.png</file>
<file>level1.txt</file>
<file>level2.txt</file>
<file>monster.png</file>
<file>pacman.png</file>
<file>wall.png</file>
</qresource>
</RCC>
98 changes: 98 additions & 0 deletions Pacman/ThreadPool.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#ifndef THREAD_POOL_H
#define THREAD_POOL_H

#include <vector>
#include <queue>
#include <memory>
#include <thread>
#include <mutex>
#include <condition_variable>
#include <future>
#include <functional>
#include <stdexcept>


class ThreadPool {
public:
ThreadPool(size_t);
void joinAll();
template<class F, class... Args>
auto enqueue(F&& f, Args&&... args)
-> std::future<typename std::result_of<F(Args...)>::type>;
~ThreadPool();
private:
// need to keep track of threads so we can join them
std::vector< std::thread > workers;
// the task queue
std::queue< std::function<void()> > tasks;

// synchronization
std::mutex queue_mutex;
std::condition_variable condition;
bool stop;
};

// the constructor just launches some amount of workers
inline ThreadPool::ThreadPool(size_t threads)
: stop(false)
{
for(size_t i = 0;i<threads;++i)
workers.emplace_back(
[this]
{
for(;;)
{
std::unique_lock<std::mutex> lock(this->queue_mutex);
while(!this->stop && this->tasks.empty())
this->condition.wait(lock);
if(this->stop && this->tasks.empty())
return;
std::function<void()> task(this->tasks.front());
this->tasks.pop();
lock.unlock();
task();
}
}
);
}


// add new work item to the pool
template<class F, class... Args>
auto ThreadPool::enqueue(F&& f, Args&&... args)
-> std::future<typename std::result_of<F(Args...)>::type>
{
typedef typename std::result_of<F(Args...)>::type return_type;

// don't allow enqueueing after stopping the pool
if(stop)
throw std::runtime_error("enqueue on stopped ThreadPool");

auto task = std::make_shared< std::packaged_task<return_type()> >(
std::bind(std::forward<F>(f), std::forward<Args>(args)...)
);

std::future<return_type> res = task->get_future();
{
std::unique_lock<std::mutex> lock(queue_mutex);
tasks.push([task](){ (*task)(); });
}
condition.notify_one();
return res;
}

// the destructor joins all threads
inline ThreadPool::~ThreadPool()
{
{
std::unique_lock<std::mutex> lock(queue_mutex);
stop = true;
}
condition.notify_all();
for(size_t i = 0;i<workers.size();++i)
workers[i].join();
}



#endif
55 changes: 55 additions & 0 deletions Pacman/creature.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#include "creature.h"
#include "gamemap.h"

Creature::Creature(GameMapPtr pmap,QPixmap image, QWidget* parent )
:m_x(0)
,m_y(0)
,m_pmap(pmap)
,m_creature_image(image)
,m_label(new QLabel(parent))
{
m_label->setPixmap(m_creature_image);
m_label->setScaledContents(true);
m_label->resize(CELL_SIZE,CELL_SIZE);
m_label->show();

}

Creature::~Creature(){}

void Creature::move(const int dx,const int dy)
{
if(m_pmap->getCell(m_x+dx,m_y-dy) != WALL )
{
m_x += dx;
m_y -= dy;
}
}

void Creature::move(const Point &point)
{
move(point.x - m_x, m_y - point.y );
}

void Creature::setPosition(const size_t x,const size_t y)
{
m_x = x;
m_y = y;
}

void Creature::setPosition(const Point &point)
{
m_x = point.x;
m_y = point.y;
}

void Creature::drawCreature()
{
m_label->move(m_x*CELL_SIZE, m_y*CELL_SIZE);
}

Point Creature::getPosition() const
{
return Point(m_x,m_y);
}

33 changes: 33 additions & 0 deletions Pacman/creature.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#ifndef CREATURE_H
#define CREATURE_H

#include "gamemap.h"
#include <QPixmap>
#include <QLabel>
#include <memory>

typedef std::shared_ptr<QLabel> QLabelPtr;
// Creature class to handle move-events and containing
//data for displaying on main window
class Creature
{
public:
const size_t CELL_SIZE = 25;
Creature(GameMapPtr pmap, QPixmap image, QWidget* parent );
virtual ~Creature();
void move(const int dx,const int dy);
void move(const Point& point);
void setPosition(const size_t x,const size_t y);
void setPosition(const Point& point);
virtual void drawCreature();
Point getPosition() const;

protected:
size_t m_x;
size_t m_y;
GameMapPtr m_pmap;
QPixmap m_creature_image;
QLabelPtr m_label;
};

#endif // CREATURE_H
Binary file added Pacman/finish.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading