added double jump and sitting state

This commit is contained in:
nihonium 2023-02-25 19:34:24 +03:00
parent 2e5c5a8dde
commit 90d07dde3f
Signed by: nihonium
GPG key ID: 0251623741027CFC
148 changed files with 13050 additions and 0 deletions

View file

@ -0,0 +1,18 @@
#include <iostream>
#include <vector>
using std::cout, std::endl;
int sumEven(const std::vector<int>& v) {
int sum = 0;
size_t s = v.size();
for (int i = 0; i < s; ++i)
if (v[i] % 2 == 0)
sum += v[i];
return sum;
}
int main() {
std::vector<int> v {4, 8, 15, 16, 23, 42};
cout << sumEven(v) << endl;
}

View file

@ -0,0 +1,58 @@
#include <iostream>
#include <vector>
#include <span>
using std::cout, std::endl, std::vector, std::span;
vector<int> lastDigits1(const vector<int>& v) {
vector<int> result;
size_t size = v.size();
for(int i = 0; i < size; ++i) {
result.push_back(v[i] % 10);
}
return result;
}
void lastDigits2(vector<int>& v) {
size_t size = v.size();
for(int i = 0; i < size; ++i) {
v[i] %= 10;
}
}
void lastDigits3(vector<int>* pv) {
size_t size = pv->size();
for(int i = 0; i < size; ++i)
(*pv)[i] %= 10;
}
void lastDigits4(span<int> sp) {
size_t size = sp.size();
for(int i = 0; i < size; ++i)
sp[i] %= 10;
}
std::ostream& operator<<(std::ostream& out, const vector<int>& v) {
cout << "[";
size_t size = v.size();
for(int i = 0; i < size; ++i)
cout << v[i] << (i == size - 1 ? "]" : " ");
return out;
}
int main() {
vector<int> meow{1, 2, 3, 12, 45, 32,313123,3245};
vector<int> result1 = lastDigits1(meow);
cout << result1 << endl;
vector<int> result2 = meow;
lastDigits2(result2);
cout << result2 << endl;
vector<int> result3 = meow;
lastDigits3(&result3);
cout << result3 << endl;
span<int> sp = meow;
lastDigits4(sp);
cout << meow << endl;
}

View file

@ -0,0 +1,52 @@
#include <iostream>
#include <utility>
#include <vector>
#include <cmath>
using std::cout, std::endl, std::pair, std::vector;
vector<pair<int, int>> factorization(int n) {
if (n == 1) {
return vector<pair<int,int>>{{1, 1}};
}
int d = 2;
int c;
vector<pair<int, int>> result;
while(n != 1) {
c = 0;
while(n % d == 0) {
c++;
n /= d;
}
if (c)
result.push_back(pair{d, c});
d++;
}
return result;
}
std::ostream& operator<<(std::ostream& out, pair<int,int> p) {
out << "{" << p.first << ", " << p.second << "}";
return out;
}
std::ostream& operator<<(std::ostream& out, vector<pair<int,int>> v) {
out << "{";
size_t size = v.size();
for(int i = 0; i < size; ++i) {
out << v[i] << (i == size - 1 ? "}" : ", ");
}
return out;
}
int main() {
vector<pair<int, int>> res = factorization(60);
cout << res << endl;
res = factorization(626215995);
cout << res << endl;
res = factorization(107);
cout << res << endl;
res = factorization(1);
cout << res << endl;
}

View file

@ -0,0 +1,27 @@
#include <iostream>
#include "time.h"
#include <string_view>
#include <string>
#include <vector>
using std::cout, std::endl, std::string, std::string_view, std::vector;
int main()
{
string t1s = "23:59:59";
string_view t1sv = t1s;
string t2s = "23:59:59";
string_view t2sv = t2s;
Time t1 = t1sv;
Time t2 = t2sv;
cout << t1 + t2 << endl;
string tss = "23:59:59 23:59:59 23:59:59";
string_view tssv = tss;
vector < Time > tsv = getTimesFromString(tss);
for (int i = 0, size = tsv.size(); i < size; ++i) {
cout << tsv[i] << endl;
}
cout << sumTimes(tsv) << endl;
}

View file

@ -0,0 +1,78 @@
#include "time.h"
#include <string>
#include <iomanip>
#include <vector>
using std::cout, std::endl, std::vector, std::string_view, std::string;
Time::Time(int hours, int minutes, int seconds)
{
mHours = hours;
mMinutes = minutes;
mSeconds = seconds;
}
Time::Time(string_view s)
{
string buf;
buf = s.substr(0, 2);
mHours = stoi(buf);
buf = s.substr(3, 2);
mMinutes = stoi(buf);
buf = s.substr(6, 2);
mSeconds = stoi(buf);
}
Time::Time():Time(0, 0, 0)
{
};
Time Time::operator+(Time b) const
{
return Time((mHours + b.mHours + (mMinutes + b.mMinutes) / 60) % 24,
(mMinutes + b.mMinutes +
(mSeconds + b.mSeconds) / 60) % 60,
(mSeconds + b.mSeconds) % 60);
}
int Time::hours() const
{
return mHours;
}
int Time::minutes() const
{
return mMinutes;
}
int Time::seconds() const
{
return mSeconds;
}
vector < Time > getTimesFromString(string_view s)
{
vector < Time > res;
for (int i = 0, size = s.size(); i < size; i += 9) {
res.push_back(Time(s.substr(i, 9)));
}
return res;
}
Time sumTimes(const vector < Time > &v)
{
Time res;
for (int i = 0, size = v.size(); i < size; ++i) {
res = res + v[i];
}
return res;
}
std::ostream & operator<<(std::ostream & out, Time t)
{
out << std::setw(2) << std::setfill('0') << t.mHours
<< ":"
<< std::setw(2) << std::setfill('0') << t.mMinutes
<< ":" << std::setw(2) << std::setfill('0') << t.mSeconds;
return out;
}

View file

@ -0,0 +1,21 @@
#pragma once
#include <string_view>
#include <iostream>
#include <vector>
using std::string_view, std::vector;
class Time {
private:
int mHours = 0, mMinutes = 0, mSeconds = 0;
public:
Time(int hours, int minutes, int seconds);
Time();
Time(string_view s);
Time operator+(Time b) const;
int hours() const; int minutes() const; int seconds() const;
friend std::ostream& operator<<(std::ostream& out, Time t);
};
Time sumTimes(const vector<Time>& v);
vector<Time> getTimesFromString(string_view s);

View file

@ -0,0 +1,34 @@
#include <iostream>
#include <string>
#include <utility>
#include <vector>
using std::string, std::pair, std::cout, std::endl, std::vector;
template <typename T>
T maximum(const vector<T>& v) {
T max{};
for(int i = 0, size = v.size(); i < size; ++i) {
if (v[i] > max)
max = v[i];
}
return max;
}
int main() {
vector<int> int_v {1,3,5,3,23,113,34,54};
cout << maximum(int_v) << endl;
vector<float> float_v {1.5,5.64,5.67,45.65,113,67.5,98.12};
cout << maximum(float_v) << endl;
vector<string> string_v {"aaaa", "dfg", "dsfdgjb", "meow", "dsfewvcv", "klafdn"};
cout << maximum(string_v) << endl;
vector<pair<int, int>> pair_v {
{113, 1},
{12, 3},
{45, 34},
{113, 113},
{112, 12233}
};
pair<int, int> res = maximum(pair_v);
cout << "(" << res.first << ", " << res.second << ")" << endl;
}

View file

@ -0,0 +1,65 @@
#include <iostream>
#include <vector>
#include <array>
#include <string>
#include <utility>
using std::cout, std::endl, std::vector, std::pair;
template <typename T, typename U>
std::ostream& operator<<(std::ostream& out, const std::pair<T, U>& p)
{
out << "(" << p.first << ", " << p.second << ")";
return out;
}
template <typename T>
std::ostream& operator<<(std::ostream& out, const std::vector<T>& v)
{
out << "[";
for (size_t i = 0; i < v.size() - 1; ++i)
out << v[i] << ", ";
if (!v.empty())
{
out << v.back();
}
out << "]";
return out;
}
template <typename T>
vector<pair<typename T::value_type,typename T::value_type>> pairing(T& xs) {
typedef typename T::value_type U;
vector<pair<U, U>> res;
size_t size = xs.size();
for (int i = 0, n = (size % 2 ? size - 1: size); i < n; i += 2)
res.push_back(pair(xs[i], xs[i+1]));
if (size % 2)
res.push_back(pair(xs[size - 1], U()));
return res;
}
int main()
{
std::vector v {10, 20, 30, 40, 50, 60};
cout << pairing(v) << endl;
std::array<std::string, 7> a {"cat", "dog", "mouse", "elephant", "tiget", "axolotl", "wolf"};
cout << pairing(a) << endl;
std::string s {"Cats and dogs!"};
cout << pairing(s) << endl;
}
/*
Программа должна напечатать:
[(10, 20), (30, 40), (50, 60)]
[(cat, dog), (mouse, elephant), (tiget, axolotl), (wolf, )]
[(C, a), (t, s), ( , a), (n, d), ( , d), (o, g), (s, !)]
*/

View file

@ -0,0 +1,42 @@
#include <iostream>
#include <string>
template <typename T>
class Manager {
private:
T* mPtr;
public:
Manager() {
mPtr = nullptr;
}
void allocate() {
mPtr = (T*)malloc(sizeof(T));
}
void construct(const T& t) {
new(mPtr) T{t};
}
T& get() {
return *mPtr;
}
void destruct() {
mPtr->~T();
}
void deallocate() {
free(mPtr);
}
};
int main() {
Manager<std::string> a;
a.allocate();
a.construct("Cats and dogs");
a.get() += " and elephants";
std::cout << a.get() << std::endl;
a.destruct();
a.construct("Sapere aude");
std::cout << a.get() << std::endl;
a.destruct();
a.deallocate();
}

View file

@ -0,0 +1,74 @@
#include <iostream>
#include <string>
#include <vector>
using std::cout, std::endl, std::string, std::vector;
template <typename T>
class Ref {
private:
T* mPtr;
public:
Ref(T& t) {
mPtr = &t;
}
Ref(Ref& t) {
mPtr = t.mPtr;
}
Ref() {
mPtr = nullptr;
}
T& get() {
return *mPtr;
}
T operator=(const T& t) {
new(mPtr) T{t};
return *mPtr;
}
T operator+(const T& t) {
return *mPtr + t;
}
T operator+=(const T& t) {
*mPtr = *mPtr + t;
return *mPtr;
}
T* operator->() {
return mPtr;
}
template <typename U>
friend std::ostream& operator<<(std::ostream& out, Ref<U> r);
};
template <typename T>
std::ostream& operator<<(std::ostream& out, Ref<T> r) {
out << *(r.mPtr);
return out;
}
void toUpper(Ref<string> r) {
for(size_t i = 0; i < r->size(); ++i)
r.get()[i] = toupper(r.get()[i]);
}
int main() {
int a = 10;
Ref<int> ra = a;
cout << ra << endl;
string s = "Cat";
Ref<string> rs = s;
rs = "Mouse";
rs += "Elephant";
cout << rs << endl;
cout << s << endl;
toUpper(s);
cout << s << endl;
vector<string> animals {"Cat", "Dogs", "Elephants", "Worms"};
vector<Ref<string>> refs {animals.begin(), animals.end()};
for (int i = 0; i < refs.size(); ++i)
cout << animals[i] << " ";
cout << endl;
}

Binary file not shown.