- 1
return new Double(Math.ceil(weight)).intValue();
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+76
return new Double(Math.ceil(weight)).intValue();
И снова autoboxing не в почете
+16
/*
Дана последовательность, содержащая от 2 до 50 слов, в каждом из которых от 1 до 8 строчных
латинских букв; между соседними словами - не менее одного пробела, за последним словом - точка.
Напечатать те слова последовательности, которые отличны от первого слова и
удовлетворяют следующему свойству: в слове нет повторяющихся букв.
*/
#include <iostream>
#include <cstring>
using namespace std;
void strComparsion(const char *str1, const char *str2, const int beginStr2, const int endStr2);
int main()
{
char arrWord[50*8+50+1] = "spros na java programmistov"
" rastet i v etom vinovat chertov android.";
int counterSpace = 0; //Счетчик пробелов
char strOneBuffer[9]; //Массив для первого слова
cout << "Na vhode: \n" << arrWord << endl;
cout << "Na vyhode: \n";
//Копируем первое слов в отдельный массив
for(int i = 0; arrWord[i-2] != ' ';i++)
{
strOneBuffer[i] = arrWord[i];
if(arrWord[i] == ' ')
{
strOneBuffer[i] = '\0';
counterSpace = i;
}
}
for(int i = counterSpace + 1, j = counterSpace + 1; arrWord[i] != '\0' ; i++)
if(arrWord[i] == ' ' || arrWord[i] =='.')
{
strComparsion(strOneBuffer, arrWord, j, i);
j = i +1;
}
return 0;
}
void strComparsion(const char *str1, const char *str2, const int beginStr2, const int endStr2)
{
//Флаги
int countSymbol = 0;
int repeatSymbol = 0;
//Сравниваем слова с первым словом
if( strlen(str1) == endStr2 - beginStr2 )
for(int i = 0, j = beginStr2; j < endStr2; i++, j++)
if(str2[j] == str1[i])
countSymbol++;
//Ищем повторяющийся буквы в слове
for(int i = beginStr2; i < endStr2; i++)
for(int j = beginStr2; j < endStr2; j++)
{
if(i == j)
continue;
if(str2[i] == str2[j])
repeatSymbol++;
}
//Выводим слово по требуеиым критериям
if(countSymbol < strlen(str1) && repeatSymbol == 0)
for(int i = beginStr2; i < endStr2; i++)
{
cout << str2[i];
if(i == endStr2 - 1)
cout << " ";
}
}
Это я писал после 6 месяцев изучения кодинга
+130
class ProducerConsumer
{
private static Semaphore semaphore = new Semaphore(1, 2);
static object locker = new object();
static int product = 0;
private static bool work = true;
private static bool valueSet = false; // why??
private static void Producer() // производитель
{
while (work)
{
Console.WriteLine("Thread Producer start");
int sqr = 0;
semaphore.WaitOne(); // декрементируем счётчик семафора
for (int i = 0; i < 15; i++)
{
sqr = i * i;
}
lock (locker) // error
{
while (valueSet)
{
Thread.Yield();
}
product += sqr;
valueSet = true;
Console.WriteLine("Product put: " + sqr);
Console.WriteLine("Product now: " + product);
}
semaphore.Release(); // выход из семафора
Thread.Sleep(5000);
}
}
private static void Consumer() // потребитель
{
const int MAX = 5;
int[] arr = new int[MAX];
int result = 0;
Random rand = new Random();
while (work)
{
Console.WriteLine("Thread Consumer start");
semaphore.WaitOne();
for (int i = 0; i < 5; i++)
{
arr[i] = rand.Next(0, 1024);
}
for (int i = 0; i < 5; i++)
{
result += arr[i];
}
result /= 5;
while (!valueSet)
{
Thread.Yield();
}
lock (locker)
{
if (product - result > 0) // исключаем отриц.кол-ва продуктов
{
product -= result;
Console.WriteLine("Product get: " + result);
}
else
{
Console.WriteLine("Product < 0");
}
valueSet = false;
Console.WriteLine("Product now: " + product);
}
semaphore.Release();
Thread.Sleep(5000);
}
}
public static void Main()
{
Thread threadProducer = new Thread(Producer);
threadProducer.Start();
Thread threadConsumer = new Thread(Consumer);
threadConsumer.Start();
Thread.Sleep(5000);
Console.WriteLine("Main thread start.");
String str = System.Console.ReadLine();
Console.ReadKey();
}
}
Корявый пример решения задачи "Producer-Consumer".
+25
unsigned char ToChar(const char& c1, const char& c2)
{
static map<char,int> mapping;
mapping['0'] = 0;
mapping['1'] = 1;
mapping['2'] = 2;
mapping['3'] = 3;
mapping['4'] = 4;
mapping['5'] = 5;
mapping['6'] = 6;
mapping['7'] = 7;
mapping['8'] = 8;
mapping['9'] = 9;
mapping['A'] = 10;
mapping['B'] = 11;
mapping['C'] = 12;
mapping['D'] = 13;
mapping['E'] = 14;
mapping['F'] = 15;
return (unsigned char)(mapping[c2] + mapping[c1] * 16);
}
int main()
{
// Assuming "vector<unsigned char> content" stores the data in Hex format, one Hex character per cell.
for(size_t i=0, j=0; i < content.size(); i+=2, j++)
{
content[j] = ToChar(content[i], content[i+1]); // one unsigned char => 2 Hex characters
}
}
Индусы на СО. Я даже не знаю, что тут самое нелепое.
http://stackoverflow.com/a/24470147/2489083
+136
switch(event->touch_point) {
case 5:
input_report_abs(data->input_dev, ABS_MT_TOUCH_MAJOR, event->pressure);
input_report_abs(data->input_dev, ABS_MT_POSITION_X, event->x5);
input_report_abs(data->input_dev, ABS_MT_POSITION_Y, event->y5);
input_report_abs(data->input_dev, ABS_MT_WIDTH_MAJOR, 1);
input_mt_sync(data->input_dev);
// printk("===x2 = %d,y2 = %d ====\n",event->x2,event->y2);
case 4:
input_report_abs(data->input_dev, ABS_MT_TOUCH_MAJOR, event->pressure);
input_report_abs(data->input_dev, ABS_MT_POSITION_X, event->x4);
input_report_abs(data->input_dev, ABS_MT_POSITION_Y, event->y4);
input_report_abs(data->input_dev, ABS_MT_WIDTH_MAJOR, 1);
input_mt_sync(data->input_dev);
// printk("===x2 = %d,y2 = %d ====\n",event->x2,event->y2);
case 3:
input_report_abs(data->input_dev, ABS_MT_TOUCH_MAJOR, event->pressure);
input_report_abs(data->input_dev, ABS_MT_POSITION_X, event->x3);
input_report_abs(data->input_dev, ABS_MT_POSITION_Y, event->y3);
input_report_abs(data->input_dev, ABS_MT_WIDTH_MAJOR, 1);
input_mt_sync(data->input_dev);
// printk("===x2 = %d,y2 = %d ====\n",event->x2,event->y2);
case 2:
input_report_abs(data->input_dev, ABS_MT_TOUCH_MAJOR, event->pressure);
input_report_abs(data->input_dev, ABS_MT_POSITION_X, event->x2);
input_report_abs(data->input_dev, ABS_MT_POSITION_Y, event->y2);
input_report_abs(data->input_dev, ABS_MT_WIDTH_MAJOR, 1);
input_mt_sync(data->input_dev);
// printk("===x2 = %d,y2 = %d ====\n",event->x2,event->y2);
case 1:
input_report_abs(data->input_dev, ABS_MT_TOUCH_MAJOR, event->pressure);
input_report_abs(data->input_dev, ABS_MT_POSITION_X, event->x1);
input_report_abs(data->input_dev, ABS_MT_POSITION_Y, event->y1);
input_report_abs(data->input_dev, ABS_MT_WIDTH_MAJOR, 1);
input_mt_sync(data->input_dev);
printk("===x1 = %d,y1 = %d ====\n",event->x1,event->y1);
default:
// printk("==touch_point default =\n");
break;
}
Автору платили за строки?
Из драйвера тачскрина ft5x0x
−96
import random
while 0<1:
inn_d=str(random.randint(100000000,999999999))
a=int(inn_d[:1])*2
b=int(inn_d[1:2])*4
c=int(inn_d[2:3])*10
d=int(inn_d[3:4])*3
e=int(inn_d[4:5])*5
f=int(inn_d[5:6])*9
g=int(inn_d[6:7])*4
l=int(inn_d[7:8])*6
m=int(inn_d[8:9])*8
x=a+b+c+d+e+f+g+l+m
y=x%11
if y%11==10:
y=0
print str(inn_d)+str(y)
Такой вот генератор ИННов
+160
$(document).ready(function()
{
$(".link-tab").click(function()
{
$(".div-tab").slideToggle();
});
$(".link-tab1").click(function()
{
$(".div-tab1").slideToggle();
});
$(".link-tab2").click(function()
{
$(".div-tab2").slideToggle();
});
$(".link-tab3").click(function()
{
$(".div-tab3").slideToggle();
});
$(".link-tab4").click(function()
{
$(".div-tab4").slideToggle();
});
$(".link-tab5").click(function()
{
$(".div-tab5").slideToggle();
});
$(".link-tab6").click(function()
{
$(".div-tab6").slideToggle();
});
$(".link-tab7").click(function()
{
$(".div-tab7").slideToggle();
});
$(".link-tab8").click(function()
{
$(".div-tab8").slideToggle();
});
});
Источник: http://www.mojaslovenia.ru/js/user.js
+164
if( [ 'someString' ].indexOf( someVar ) !== -1 ) return;
Предлагаю объявить конкурс на самую дурацкую замену конструкции if (someVar === 'someString') return;
+143
using System;
using System.Text;
public class Test
{
public static void Main()
{
object obj = "Suck my balls";
string str1 = "Suck my balls";
string str2 = new StringBuilder().Append("Suck my ").Append("balls").ToString();
Console.WriteLine(obj==str1);//True
Console.WriteLine(str2==str1);//True
Console.WriteLine(obj==str2);//False
}
}
Нетранзитивный дотнет или головоломка на ночь
+128
@keyframes shadow{
from {
-webkit-box-shadow: 0px 0px 55px 10px rgba(168,207,255,40);
-moz-box-shadow: 0px 0px 55px 10px rgba(168,207,255,40);
box-shadow: 0px 0px 55px 10px rgba(168,207,255,40);
-webkit-box-shadow: 0px 0px 54px 10px rgba(168,207,255,40);
-moz-box-shadow: 0px 0px 54px 10px rgba(168,207,255,40);
box-shadow: 0px 0px 54px 10px rgba(168,207,255,40);
-webkit-box-shadow: 0px 0px 53px 10px rgba(168,207,255,40);
-moz-box-shadow: 0px 0px 53px 10px rgba(168,207,255,40);
box-shadow: 0px 0px 53px 10px rgba(168,207,255,40);
.......
-webkit-box-shadow: 0px 0px 1px 10px rgba(168,207,255,40);
-moz-box-shadow: 0px 0px 1px 10px rgba(168,207,255,40);
box-shadow: 0px 0px 1px 10px rgba(168,207,255,40);
}
to{
-webkit-box-shadow: 0px 0px 1px 10px rgba(168,207,255,40);
-moz-box-shadow: 0px 0px 1px 10px rgba(168,207,255,40);
box-shadow: 0px 0px 1px 10px rgba(168,207,255,40);
.......
-webkit-box-shadow: 0px 0px 53px 10px rgba(168,207,255,40);
-moz-box-shadow: 0px 0px 53px 10px rgba(168,207,255,40);
box-shadow: 0px 0px 53px 10px rgba(168,207,255,40);
-webkit-box-shadow: 0px 0px 54px 10px rgba(168,207,255,40);
-moz-box-shadow: 0px 0px 54px 10px rgba(168,207,255,40);
box-shadow: 0px 0px 54px 10px rgba(168,207,255,40);
-webkit-box-shadow: 0px 0px 55px 10px rgba(168,207,255,40);
-moz-box-shadow: 0px 0px 55px 10px rgba(168,207,255,40);
box-shadow: 0px 0px 55px 10px rgba(168,207,255,40);
}
}
#progressShadow{
height:25px;
margin:-28px 0 0 30px;
border-radius: 10px;
position: absolute;
-webkit-animation: shadow 1s linear infinite;
-moz-animation: shadow 1s linear infinite;
animation: shadow 1s linear infinite;
}
Чувак хотел создать эффект пульсацию с CSS и расчет сделал от 55px до 1px и от 1px до 55px )))