- 1
- 2
- 3
- 4
- 5
#include <iostream>
int main()
{
system("calc");
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+36
#include <iostream>
int main()
{
system("calc");
}
Калькулятор на C++? Да пожалуйста.
+24
int MyForm::modelId(int button, bool rarefied, bool grouped)
{
if (button == 4)
return 9;
else
{
Q_ASSERT(button == 1 || button == 2 || button == 3);
if (!rarefied)
return (button - 1);
else
{
if (!grouped)
return 3 + (button - 1);
else
return 6 + (button - 1);
}
}
}
Энумы? Не, не слышал.
+16
char tab1[22][8]={"program","var","begin","end","int","float","bool","if","then","else","for","to","do","while","readln","writeln","as","||","!","&&","true","false"};
char tab2[18][3]={"==","<",">","+","-","*","/","(",")",".",",",";"," ","!=","<=",">=",10};
//Много кода
if(!strcmp("program",st.top())&&!strcmp("program",&mas[j][0]))
{
st.pop();
j++;
}
else
if(!strcmp("var",st.top())&&!strcmp("var",&mas[j][0]))
{
st.pop();
j++;
}
else
if(!strcmp("begin",st.top())&&!strcmp("begin",&mas[j][0]))
{
st.pop();
j++;
}
else
if(!strcmp("end",st.top())&&!strcmp("end",&mas[j][0]))
{
st.pop();
j++;
}
else
if(!strcmp("int",st.top())&&!strcmp("int",&mas[j][0]))
{
st.pop();
j++;
}
else
if(!strcmp("float",st.top())&&!strcmp("float",&mas[j][0]))
{
st.pop();
j++;
}
//Еще строк 200 такого
+14
int main(int argc, char* argv[])
{
SetConsoleCP(1251);// установка кодовой страницы win-cp 1251 в поток ввода
SetConsoleOutputCP(1251); // установка кодовой страницы win-cp 1251 в поток вывода
setlocale(LC_ALL,"Ukrainian");
if(argc<2)
{
argv[1] = (char*)malloc(500*sizeof(char));
//printf("Vvedit' imya vxidnogo failu: \n");
//scanf("%s",argv[1]);
argv[1]="1.txt";
}
+24
template <typename IdType, class Tag>
class id {
public:
typedef IdType value_type;
explicit id(value_type val)
: value(val)
{}
bool operator==(id rhs)
{
return rhs.value == value;
}
bool operator!=(id rhs)
{
return rhs.value != value;
}
value_type value;
};
#define HASKELL_NEWTYPE(type_name, value_type) struct __##type_name##_tag__ {}; \
typedef ::id<value_type, __##type_name##_tag__> type_name
Когда newtype нет, но очень хочется.
http://ideone.com/VRu56j
Простите за синтетику
+9
y=fopen(lex,"w+");
fclose(y);
FILE *r=fopen(result,"w+");
fclose(r);
FILE *k=fopen("pryklad.obj","w+");
fclose(k);
+12
class Thread
{
public:
Thread(const Thread&);
Thread() : handle(NULL), running(false), finished(false)
{
handle = (HANDLE)(_beginthreadex(NULL, 0, &(Thread::threadRun), this, CREATE_SUSPENDED, NULL));
}
~Thread()
{
if(isRunning()) {
TerminateThread(handle, 0);
}
CloseHandle(handle);
}
void start(void* arg)
{
if(isRunning() || isFinished()) {
throw Exception("Thread is running or finished!");
} else {
this->arg = arg;
ResumeThread(handle);
}
}
void pause()
{
if(isRunning()) {
SuspendThread(handle);
} else {
throw Exception("Thread is not running or finished!");
}
}
void resume()
{
if(!(isRunning())) {
throw Exception("Thread is finished!");
} else {
ResumeThread(handle);
}
}
void stop()
{
if(isRunning()) {
TerminateThread(handle, 0);
running = false;
finished = true;
throw Exception("Thread stopped!");
} else {
throw Exception("Thread is not running or finished!");
}
}
void setPriority(ThreadPriority priority)
{
if(isFinished()) {
throw Exception("Thread is finished!");
} else {
switch(priority) {
case ThreadPriorityLow:
SetThreadPriority(handle, THREAD_PRIORITY_LOWEST);
break;
case ThreadPriorityNormal:
SetThreadPriority(handle, THREAD_PRIORITY_NORMAL);
break;
case ThreadPriorityHigh:
SetThreadPriority(handle, THREAD_PRIORITY_HIGHEST);
break;
default:
throw Exception("Invalid priority!");
break;
}
}
}
bool isRunning()
{
return (running);
}
bool isFinished()
{
return (finished);
}
protected:
virtual void run(void *arg) = 0;
private:
static unsigned int __stdcall threadRun(void *arg)
{
Thread *thread = static_cast<Thread*>(arg);
thread->running = true;
thread->run(thread->arg);
thread->running = false;
thread->finished = true;
_endthreadex(0);
return (0);
}
void *arg;
HANDLE handle;
bool running;
bool finished;
};
Из предыдущей оперы.
+7
template<typename T>
class Enumerable
{
public:
Enumerable() : enumerableInProcess(false) { };
virtual void begin() = 0;
virtual void end() = 0;
virtual bool enumeration(T* item) = 0;
protected:
bool enumerableInProcess;
};
template<typename T>
class List : Enumerable<T*>
{
public:
class ListItem
{
public:
friend class List;
T item;
ListItem(T item) : item(item), next(nullptr), previous(nullptr)
{
}
private:
class ListItem* next;
class ListItem* previous;
};
/* ... */
void begin()
{
if(enumerableInProcess) {
throw Exception("Error Enumerable!");
}
enumerableInProcess = true;
enumerationItem = first;
}
bool enumeration(T** item)
{
if(enumerableInProcess) {
if(enumerationItem != nullptr) {
(*item) = &(enumerationItem->item);
enumerationItem = enumerationItem->next;
return (true);
} else {
(*item) = nullptr;
return (false);
}
} else {
throw Exception("Error Enumerable!");
}
}
bool enumeration(ListItem **listItem)
{
if(enumerableInProcess) {
if(enumerationItem != nullptr) {
(*listItem) = enumerationItem;
enumerationItem = enumerationItem->next;
return (true);
} else {
(*listItem) = nullptr;
return (false);
}
} else {
throw Exception("Error Enumerable!");
}
}
void end()
{
if(!enumerableInProcess) {
throw Exception("Error Enumerable!");
}
enumerableInProcess = false;
}
private:
const int size;
int count;
ListItem *first;
ListItem *last;
ListItem *enumerationItem;
};
void list_t_1()
{
List<int> list(8);
List<int>::ListItem *item;
list.add(1);
list.add(2);
list.add(4);
list.add(8);
list.add(16);
list.begin();
while(list.enumeration(&item))
{
printf("%i\n", (item->item));
}
list.end();
}
+25
if (delitel.number.at(0) == '0')
{
chastnoe.number.push_back('D');
chastnoe.number.push_back('e');
chastnoe.number.push_back('L');
chastnoe.number.push_back('e');
chastnoe.number.push_back('N');
chastnoe.number.push_back('i');
chastnoe.number.push_back('e');
chastnoe.number.push_back(' ');
chastnoe.number.push_back('n');
chastnoe.number.push_back('a');
chastnoe.number.push_back(' ');
chastnoe.number.push_back('0');
return chastnoe;
}
Из чьей-то реализации длинной арифметики
+27
inline double poly(double x, const double *c, int k) const {
double y = c[k];
switch (k) {
case 15: y = y * x + c[14];
case 14: y = y * x + c[13];
case 13: y = y * x + c[12];
case 12: y = y * x + c[11];
case 11: y = y * x + c[10];
case 10: y = y * x + c[ 9];
case 9: y = y * x + c[ 8];
case 8: y = y * x + c[ 7];
case 7: y = y * x + c[ 6];
case 6: y = y * x + c[ 5];
case 5: y = y * x + c[ 4];
case 4: y = y * x + c[ 3];
case 3: y = y * x + c[ 2];
case 2: y = y * x + c[ 1];
case 1: y = y * x + c[ 0];
case 0: break;
}
return y;
}
Схема Горнера для вычисления значения многочлена в точке