+84
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
for (int hasFirstPass = 0; hasFirstPass <= 1; ++hasFirstPass) {
for (int firstPassOffsetLeft = 0; firstPassOffsetLeft <= hasFirstPass; ++firstPassOffsetLeft) {
for (int firstPassOffsetRight = 0; firstPassOffsetRight <= hasFirstPass; ++firstPassOffsetRight) {
for (int firstPassOffsetTop = 0; firstPassOffsetTop <= hasFirstPass * 2; ++firstPassOffsetTop) {
for (int firstPassOffsetBottom = 0; firstPassOffsetBottom <= hasFirstPass * 2; ++firstPassOffsetBottom) {
for (int hasSecondPass = 0; hasSecondPass <= 1; ++hasSecondPass) {
for (int secondPassOffsetLeft = 0; secondPassOffsetLeft <= hasSecondPass * 2; ++secondPassOffsetLeft) {
for (int secondPassOffsetRight = 0; secondPassOffsetRight <= hasSecondPass * 2; ++secondPassOffsetRight) {
for (int secondPassOffsetTop =
0; secondPassOffsetTop <= hasSecondPass; ++secondPassOffsetTop) {
for (int secondPassOffsetBottom =
0; secondPassOffsetBottom <= hasSecondPass; ++secondPassOffsetBottom) {
// ... some processing code
}
}
}
}
}
}
}
}
}
}
Есть некоторая обработка прямоугольника, проводящаяся в два этапа. Причём на первом этапе отступ от правого и левого края может быть не более 1, от верхнего и нижнего не более 2. На втором этапе наоборот. Каждый из этапов может отсутствовать, в таком случае естественно перебирать варианты отступа для этого этапа не нужно.
Этот код перебирает все возможные варианты такой обработки.
burdakovd,
27 Августа 2010
+173
- 1
$karkas = tr(bgcolor("D9EDFB"), td(w("1%").style("").valign("top"),br()).td(valign("top"), hr(noshade().size(1).color("D9EDFB")).table(cs(0).cp(10).border(0), tr(no(), td(no(), 'текст'...
Все знают, что хорошим стилем написанием сайта является отделение кода от дизайна. Но то, что я увидел в самописной CMS, детище прошлого PHP-кодера, повергло меня в тихий ужас.
Каждый HTML-тег со всеми атрибутами был переопределён в отдельную функцию со своими параметрами. Нашлось место даже для замечательной функции br().
[url]http://ithappens.ru/story/3663[/url]
Uchkuma,
19 Июля 2010
+157
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
<?
@$ok=$HTTP_POST_VARS["ok"];
@$user=$HTTP_POST_VARS["user"];
@$pwd=$HTTP_POST_VARS["pwd];
if(!isset($ok))
echo "<form action=.$2.php. method=POST>"
."Name<input type=text name user><br>"
."Password<input type=password name=pwd><br>"
."<input type=submit name=ok value=Войти>"
."</form>";
else
{
if(($user="Demo")&&($pwd=="Demo"))
echo "Wellcome";
else
echo "Access Blocked";
}
?>
Говорят, что это не говнокод.
kal1sha,
14 Июля 2010
+135
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
int Xor4Bit_2 (unsigned char data)
{
unsigned char result = data;
while (data != 0)
{
result ^= data & 1;
data >>= 1;
}
result &= 1;
return result;
}
вот как студенты получают xor битов числа
это же нужно так извратить простой рабочий алгоритм
int Xor4Bit_2 (unsigned char data)
{
int result = 0
while (data != 0)
{
result ^= data & 1;
data >>= 1;
}
return result;
}
получил данный код после измышлизмов знакомого студента, перед этим дав ему рабочий вариант, мдя...
ageron,
04 Июля 2010
+170
- 1
- 2
require_once('configure.php');
require('configure.php');
надо быть _увереным_ в своем коде
sogekoder,
05 Июня 2010
+80
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
private String nextUTF8Character() throws IOException, CharacterCodingException
{
int iCodePoint = 0;
int byte1, byte2, byte3, byte4;
byte1 = is.read();
if (byte1 == -1)
return null;
// проверяем является ли первый бит нулевым
if ((byte1 & 0x80) == 0)
{
// один байт
iCodePoint = byte1 & 0x7F;
return new String(Character.toChars(iCodePoint));
}
byte2 = is.read();
if (byte2 == -1)
return null;
if ((byte1 & 0xE0) == 0xC0 && (byte2 & 0xC0) == 0x80)
{
// два байта
iCodePoint = ((byte1 & 0x1F) << 6) | (byte2 & 0x3F);
if (iCodePoint > 0x7F)
return new String(Character.toChars(iCodePoint));
else
throw new CharacterCodingException();
}
byte3 = is.read();
if (byte3 == -1)
return null;
if ((byte1 & 0xF0) == 0xE0 && (byte2 & 0xC0) == 0x80 && (byte3 & 0xC0) == 0x80)
{
// три байта
iCodePoint = ((byte1 & 0x0F) << 12) | ((byte2 & 0x3F) << 6) | (byte3 & 0x3F);
if (iCodePoint > 0x7FF)
return new String(Character.toChars(iCodePoint));
else
throw new CharacterCodingException();
}
byte4 = is.read();
if (byte4 == -1)
return null;
if ((byte1 & 0xF8) == 0xF0 && (byte2 & 0xC0) == 0x80 &&
(byte3 & 0xC0) == 0x80 && (byte4 & 0xC0) == 0x80)
{
// четыре байта
iCodePoint = ((byte1 & 0x07) << 18) | ((byte2 & 0x3F) << 12) |
((byte3 & 0x3F) << 6) | (byte4 & 0x3F);
if (iCodePoint > 0x0FFFF)
return new String(Character.toChars(iCodePoint));
else
throw new CharacterCodingException();
}
throw new CharacterCodingException();
}
Мегаоптимизированный код для получения букафф в кодироффке UTFфф-8
По данным профилировщика именно этот фрагмент самый тормозной в моей сетевой проге
Max ID,
20 Мая 2010
+97
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
/// До этой строчки еще больше 1000 строк кода (И это всё в ОДНОЙ процедур)
finally
if Main.RecordCount > 0
then Main.First;
Main.EnableControls;
Panel2.Color:=clLime;
lbTimeSpend.Caption:='Âðåìÿ çàòðà÷åíî:'+TimeToStr(time()-TimeWork);
end;
Exit;
try
if TmpCollect_Skd.IsSelectAll then
begin
Askd_count := TmpCollect_Skd.RxDBGrid1.DataSource.DataSet.RecordCount;
end
/// После этой строки еще более 1000 строк кода всё в этой же процедуре!
Продолжим. Вот так люди используют Exit;
goodron,
28 Апреля 2010
+144.9
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
class SmoothingModeManager
{
public:
SmoothingModeManager(Context* context, Gdiplus::SmoothingMode mode = Gdiplus::SmoothingModeHighQuality);
virtual ~SmoothingModeManager();
protected:
Context* context_;
};
////////////////////////
SmoothingModeManager::SmoothingModeManager(Context* context, Gdiplus::SmoothingMode mode)
: context_(context)
{
context_->getCanvas()->SetSmoothingMode(mode);
}
SmoothingModeManager::~SmoothingModeManager()
{
context_->getCanvas()->SetSmoothingMode(Gdiplus::SmoothingModeNone);
}
Инициализируем класс и контекст со сглаживанием до конца метода.
Altravert,
26 Февраля 2010
+55.3
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
#include<iostream>
#include<math.h>
//#include<csdio>
using namespace std;
void main(){
//char*s1=new char[0]
int i=0;
do
char*s1=new char[0];
cout<<'write s1: ';
cin>>s1[i];
i=i+1;
while (*s1[i]=="\0");
for(int j=1, j==i, j++)
cout<<s1[j];
cout<<endl;
delete []s1;
}
Вот такую поделку мне прислали на проверку с жалобой "не работает".
uncle Lem,
06 Января 2010
+122.4
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
/* sent by Stephan Hughson - 2003 */
/* must be compiled with cc or g++*/
#include <stdio.h>
int main(int t,int _,char*a)
{return!0<t?t<3?main(-79,-13,a+main(-87,1-_,
main(-86, 0, a+1 )+a)):1,t<_?main(t+1, _, a ):3,main ( -94, -27+t, a
)&&t == 2 ?_<13 ?main ( 2, _+1, "%s %d %d\n" ):9:16:t<0?t<-72?main(_,
t,"@n'+,#'/*{}w+/w#cdnr/+,{}r/*de}+,/*{*+,/w{%+,/w#q#n+,/#{l,+,/n{n+\
,/+#n+,/#;#q#n+,/+k#;*+,/'r :'d*'3,}{w+K w'K:'+}e#';dq#'l q#'+d'K#!/\
+k#;q#'r}eKK#}w'r}eKK{nl]'/#;#q#n'){)#}w'){){nl]'/+#n';d}rw' i;# ){n\
l]!/n{n#'; r{#w'r nc{nl]'/#{l,+'K {rw' iK{;[{nl]'/w#q#\
n'wk nw' iwk{KK{nl]!/w{%'l##w#' i; :{nl]'/*{q#'ld;r'}{nlwb!/*de}'c \
;;{nl'-{}rw]'/+,}##'*}#nc,',#nw]'/+kd'+e}+;\
#'rdq#w! nr'/ ') }+}{rl#'{n' ')# }'+}##(!!/")
:t<-50?_==*a ?putchar(a[31]):main(-65,_,a+1):main((*a == '/')+t,_,a\
+1 ):0<t?main ( 2, 2 , "%s"):*a=='/'||main(0,main(-61,*a, "!ek;dc \
i@bK'(q)-[w]*%n+r3#l,{}:\nuwloca-O;m .vpbks,fxntdCeghiry"),a+1);}
Вот результат работы программы(всё не вместилось):
On the first day of Christmas my true love gave to me
a partridge in a pear tree.
On the second day of Christmas my true love gave to me
two turtle doves
and a partridge in a pear tree.
...
On the eighth day of Christmas my true love gave to me
eight maids a-milking, seven swans a-swimming,
six geese a-laying, five gold rings;
four calling birds, three french hens, two turtle doves
and a partridge in a pear tree.
On the ninth day of Christmas my true love gave to me
nine ladies dancing, eight maids a-milking, seven swans a-swimming,
six geese a-laying, five gold rings;
four calling birds, three french hens, two turtle doves
and a partridge in a pear tree.
On the tenth day of Christmas my true love gave to me
ten lords a-leaping,
nine ladies dancing, eight maids a-milking, seven swans a-swimming,
six geese a-laying, five gold rings;
four calling birds, three french hens, two turtle doves
and a partridge in a pear tree.
On the eleventh day of Christmas my true love gave to me
eleven pipers piping, ten lords a-leaping,
nine ladies dancing, eight maids a-milking, seven swans a-swimming,
six geese a-laying, five gold rings;
four calling birds, three french hens, two turtle doves
and a partridge in a pear tree.
On the twelfth day of Christmas my true love gave to me
twelve drummers drumming, eleven pipers piping, ten lords a-leaping,
nine ladies dancing, eight maids a-milking, seven swans a-swimming,
six geese a-laying, five gold rings;
four calling birds, three french hens, two turtle doves
and a partridge in a pear tree.
guest,
28 Июня 2009