135 lines
2.6 KiB
C++
135 lines
2.6 KiB
C++
// Includes
|
|
#include <iostream>
|
|
#include <map>
|
|
#include <algorithm>
|
|
#include <functional>
|
|
#include <iterator>
|
|
#include <vector>
|
|
#include "foo.h"
|
|
#include "main-formatted.hh"
|
|
#include <cstdlib>
|
|
#include <ctime>
|
|
#include <cstdint>
|
|
|
|
// Macros
|
|
#define MAGIC_NUMBER 0xdeadbeef
|
|
#define MAGIC_FUNCTION(a,b) while ((a) % (b) != 0) { \
|
|
(a)--; \
|
|
}
|
|
|
|
namespace ns1 { namespace ns2 {
|
|
|
|
template <typename T, int size> bool is_sorted(T(&array)[size]) {
|
|
return std::adjacent_find(array, array + size, std::greater<T>()) ==
|
|
array + size;
|
|
}
|
|
|
|
|
|
class C {
|
|
public:
|
|
C() : a_(1), _b(2), m_c("3") {}
|
|
virtual ~C() noexcept {
|
|
|
|
}
|
|
|
|
auto f() const noexcept -> int {
|
|
return static_cast<int>(a_);
|
|
}
|
|
|
|
private:
|
|
double a_;
|
|
int _b;
|
|
std::string m_c;
|
|
};
|
|
}
|
|
}
|
|
|
|
auto someFunctionCall(int8_t a,
|
|
float *b) -> int {
|
|
return *b;
|
|
}
|
|
|
|
struct test {
|
|
int a,b;
|
|
const char* c;
|
|
};
|
|
|
|
std::vector<uint32_t> returnVector( uint32_t* LongNameForParameter1,
|
|
double* LongNameForParameter2,
|
|
const float& LongNameForParameter3,
|
|
std::map<std::string,int32_t>& LongNameForParameter4) {
|
|
|
|
//TODO: This is a long comment that allows you to understand how long comments will be trimmed. Here should be deep thought but it's just not right time for this
|
|
|
|
for (auto& i: LongNameForParameter4) {
|
|
auto b = someFunctionCall(static_cast<int16_t>(*LongNameForParameter2),reinterpret_cast<float*>(LongNameForParameter2));
|
|
i.second++;
|
|
}
|
|
|
|
do {
|
|
auto a = 100;
|
|
if (a)
|
|
a--;
|
|
else
|
|
a++;
|
|
} while (false);
|
|
|
|
test demo[] =
|
|
{
|
|
{56, 23, "hello"},
|
|
{-1, 93463, "world"},
|
|
{7, 5, "!!" }
|
|
};
|
|
|
|
auto b = *LongNameForParameter1 > LongNameForParameter3
|
|
? 1
|
|
: 2;
|
|
|
|
return {};
|
|
}
|
|
|
|
int main() {
|
|
std::srand(std::time(0));
|
|
|
|
int list[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
|
|
|
|
|
|
using ns1::ns2::is_sorted;
|
|
do {
|
|
std::random_shuffle(list, list + 9);
|
|
} while (is_sorted(list));
|
|
|
|
switch(43) {
|
|
case 42:
|
|
{
|
|
// indented?
|
|
}
|
|
break;
|
|
case 43:
|
|
return 0;
|
|
}
|
|
|
|
int score = 0;
|
|
|
|
do {
|
|
std::cout << "Current list: ";
|
|
std::copy(list, list + 9, std::ostream_iterator<int>(std::cout, " "));
|
|
|
|
int rev;
|
|
while (true) {
|
|
std::cout << "\nDigits to reverse? ";
|
|
std::cin >> rev;
|
|
if (rev > 1 && rev < 10)
|
|
break;
|
|
std::cout << "Please enter a value between 2 and 9.";
|
|
}
|
|
|
|
++score;
|
|
std::reverse(list, list + rev);
|
|
} while (!is_sorted(list));
|
|
|
|
std::cout << "Congratulations, you sorted the list.\n"
|
|
<< "You needed " << score << " reversals." << std::endl;
|
|
return 0;
|
|
}
|