- 1
(selectedChessman ?: selected)->unselect();
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+48
(selectedChessman ?: selected)->unselect();
да уж
+51
template<class T, size_t N>
constexpr size_t sa(T (&)[N])
{
return N;
};
static std::memory_order mmo[] =
{
memory_order_relaxed,
memory_order_consume,
memory_order_acquire,
memory_order_release,
memory_order_acq_rel,
memory_order_seq_cst
};
std::memory_order current_program_memory_order()
{
return mmo[rand()%sa(mmo)];
}
void current_program_memory_barier()
{
std::atomic_thread_fence(current_program_memory_order());
}
+54
class SpinLock
{
std::atomic_flag lck;
public:
SpinLock(){
unlock();
}
__forceinline void lock(){
while (lck.test_and_set(std::memory_order_acquire)){
}
}
__forceinline void unlock(){
lck.clear(std::memory_order_release);
}
};
+62
if( state != !val )
{
state = !val;
}
Переключение. Обе переменные булевские.
+51
void main() {
system("color 04");
setlocale(LC_ALL, "rus");
if (start == false) {
logos();
loading();
start = true;
system("cls");
}
if (get_hero_s == false) {
get_hero();
get_hero_s = true;
}
menu();
map();
if (go_went_gone == 1) {
system("cls");
cout << "\nВы напали на оборотня в тёмном лесу\n";
loading();
Sleep(1400);
fight("werewolf");
go_went_gone = 0;
main();
}
else if (go_went_gone == 3) {
system("cls");
cout << "\nВы напали на лучника в мрачном поле\n";
loading();
Sleep(1400);
fight("archer");
go_went_gone = 0;
main();
}
if (go_went_gone == 2) {
system("cls");
cout << "\nВы напали на гоблина в тёмном лесу\n";
loading();
Sleep(1400);
fight("werewolf");
go_went_gone = 0;
main();
}
else if (go_went_gone == 4) {
system("cls");
cout << "\nВы напали на лучника на костяного лучника в подземелье \n";
loading();
Sleep(1400);
fight("archer");
go_went_gone = 0;
main();
}
Рекурсия мейна, и это курсовая работа!!
+55
bool validateIp(std::string& ip) {
if( ip.length() == 0 ) {
return false;
}
if( ip[0] == '.' ) {
return false;
}
// Проверка на наличие 3 точек
int cp = 0;
for( int i = 0; i < ip.length(); i++ ) {
if( ip[i] == '.' ) {
cp++;
}
}
if( cp != 3 ) {
std::cout << "проверка на 3 точки" << std::endl;
return false;
}
//=====================
// Проверка на 2 точки подряд
for( int i = 0; i < ip.length()-1; i++ ) {
if( ip[i] == '.' && ip[i+1] == '.' ) {
std::cout << "проверка на 2 точки подряд" << std::endl;
return false;
}
}
//===========================
//Проверка на больше 3 цифр подряд
int i = 0;
int j = 0;
for( i = 0; i < ip.length(); i++ ) {
for( j = i; j < i+4 && j < ip.length(); j++ ) {
if( j == i+3 && ip[j] != '.' ) {
std::cout << "проверка на 4 цифры подряд" << std::endl;
return false;
}
if( ip[j] == '.' ) {
i = j;
break;
}
}
}
return true;
//============================
}
Валидация IP-адреса
+51
while (w.pollEvent(event)) {
if ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Period)) {
ip += ".";
}
if ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Num0)) {
ip += "0";
}
if ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Num1)) {
ip += "1";
}
if ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Num2)) {
ip += "2";
}
if ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Num3)) {
ip += "3";
}
if ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Num4)) {
ip += "4";
}
if ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Num5)) {
ip += "5";
}
if ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Num6)) {
ip += "6";
}
if ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Num7)) {
ip += "7";
}
if ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Num8)) {
ip += "8";
}
if ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Num9)) {
ip += "9";
}
if ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::BackSpace) && ip.length() > 0) {
ip.erase(ip.end() - 1, ip.end());
}
if ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Return)) {
if (validateIp(ip)) {
Text c("Connection...", f);
c.setColor(Color::Black);
c.setPosition(100, 20);
w.draw(c);
w.display();
return ip;
} else {
ip.erase(ip.begin(), ip.end());
wrongAnswer = true;
}
}
if (event.type == Event::Closed) {
w.close();
return 0;
}
}
Ввод IP-адреса в интерфейсе игры
+49
#include <iostream>
int get_number() {
return 5;
}
int magic_number(int foo()) {
return foo();
}
int main(void)
{
std::cout << magic_number(get_number) << std::endl;
}
http://ideone.com/TbV0jD
+51
//Sets the color(background and foreground)
void Console::SetColor(){
#ifdef _WIN32
SetConsoleTextAttribute(hConsole, FGColor | BGColor);
#else
string clr = "\033[";
clr += BGColor;
clr += ";";
clr += FGColor;
clr += "m";
cout << clr;
#endif
}
Изменение цвета текста и фона консоли
+52
// round up the blockSize to fit an integer number of pointers...
m_blockSize = static_cast<QMPoolSize>(sizeof(QFreeBlock));//start with one
uint_fast16_t nblocks = uf16_1; //# free blocks in a memory block
while (m_blockSize < static_cast<QMPoolSize>(blockSize)) {
m_blockSize += static_cast<QMPoolSize>(sizeof(QFreeBlock));
++nblocks;
}
в догонку к #17616. делим на 4 с округлением, с помощью цикла.
P.S. касты и цикл само собой разумеется в ж не нужны:
m_blockSize = (blockSize + sizeof(QFreeBlock)-1) & ~(sizeof(QFreeBlock)-1);
nblocks = m_blockSize / sizeof(QFreeBlock);