- 1
- 2
- 3
- 4
- 5
If bd12tc->mes!=num_month
st_mes=num_month
Else
st_mes=bd12tc->mes
EndIf
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+97
If bd12tc->mes!=num_month
st_mes=num_month
Else
st_mes=bd12tc->mes
EndIf
Clipper
Перевожу на работе старую программку (писалась больше 12 лет назад) в Delphi, нашёл вот такое
+97
if (stage < 4 || stage > 4) {
loadWizard();
}
ситуации или-или (с)
+97
TPicture = class(TInterfacedPersistent, IStreamPersist)
....
property Bitmap: TBitmap read GetBitmap write SetBitmap;
property Icon: TIcon read GetIcon write SetIcon;
property Metafile: TMetafile read GetMetafile write SetMetafile;
....
procedure TPicture.ForceType(GraphicType: TGraphicClass);
begin
if not (Graphic is GraphicType) then
begin
FGraphic.Free; // 0_0 йобаный стыд!!
FGraphic := nil;
FGraphic := GraphicType.Create;
FGraphic.OnChange := Changed;
FGraphic.OnProgress := Progress;
Changed(Self);
end;
end;
function TPicture.GetBitmap: TBitmap;
begin
ForceType(TBitmap);
Result := TBitmap(Graphic);
end;
function TPicture.GetIcon: TIcon;
begin
ForceType(TIcon);
Result := TIcon(Graphic);
end;
function TPicture.GetMetafile: TMetafile;
begin
ForceType(TMetafile);
Result := TMetafile(Graphic);
end;
Взято из "ДНК", т.е. VCL от Delphi7. unit graphics.pas
Методы get-аксессоры свойств Bitmap, Icon и Metafile вызывают ForceType(). Шутка в том, что если картинка у вас другого типа - то она будет ВНЕЗАПНО выпилена насовсем, стоит только прочитать(sic!) не то свойство объекта класса TPicture.
Наступил сам на эти грабли и потратил драгоценный, час пока понял в чем дело.
+97
if MethodName = AnsiUpperCase('Зробити_все_чудово_пречудово') then
begin
Screen.Cursor := crHourGlass;
try
for LowIndex := 0 to 200 do
begin
Application.ProcessMessages;
Sleep(10);
end;
ShowInfo('Тепер все чудово-пречудово.'#13#10'Посміхніться!');
finally
Screen.Cursor := crDefault;
end;
end
Внутренний скрипотвый язык
+97
var sum,x1,x2,y1,y2,i,k,l,m,n:longint;
a:array[1..1000,1..2] of longint;
b:array[1..100,1..100] of longint;
procedure ws(x,y,c:longint);
var k:longint;
begin
if (not((x-2<1)or(y-1<1)or(x-2>n)or(y-1>N))and(b[x-2,y-1]=0)) then begin inc(m);a[m,1]:=x-2;a[m,2]:=y-1;b[x-2,y-1]:=b[x,y]+1;end;
if (not((x+2<1)or(y-1<1)or(x+2>n)or(y-1>N))and(b[x+2,y-1]=0)) then begin inc(m);a[m,1]:=x+2;a[m,2]:=y-1;b[x+2,y-1]:=b[x,y]+1;end;
if (not((x-1<1)or(y-2<1)or(x-1>n)or(y-2>N))and(b[x-1,y-2]=0)) then begin inc(m);a[m,1]:=x-1;a[m,2]:=y-2;b[x-1,y-2]:=b[x,y]+1;end;
if (not((x+1<1)or(y-2<1)or(x+1>n)or(y-1>N))and(b[x+1,y-2]=0)) then begin inc(m);a[m,1]:=x+1;a[m,2]:=y-2;b[x+1,y-2]:=b[x,y]+1;end;
if (not((x-2<1)or(y+1<1)or(x-2>n)or(y+1>N))and(b[x-2,y+1]=0)) then begin inc(m);a[m,1]:=x-2;a[m,2]:=y+1;b[x-2,y+1]:=b[x,y]+1;end;
if (not((x+2<1)or(y+1<1)or(x+2>n)or(y+1>N))and(b[x+2,y+1]=0)) then begin inc(m);a[m,1]:=x+2;a[m,2]:=y+1;b[x+2,y+1]:=b[x,y]+1;end;
if (not((x-1<1)or(y+2<1)or(x-1>n)or(y+2>N))and(b[x-1,y+2]=0)) then begin inc(m);a[m,1]:=x-1;a[m,2]:=y+2;b[x-1,y+2]:=b[x,y]+1;end;
if (not((x+1<1)or(y+2<1)or(x+1>n)or(y+2>N))and(b[x+1,y+2]=0)) then begin inc(m);a[m,1]:=x+1;a[m,2]:=y+2;b[x+1,y+2]:=b[x,y]+1;end;
end;
begin
reset(input,'input.txt');
rewrite(output,'output.txt');
read(n);
read(x1,y1);
read(x2,y2);
b[1,1]:=0;
a[1,1]:=x1;a[1,2]:=y1;
i:=0;m:=1;l:=1;
while i<=m do begin inc(i);
ws(a[i,1],a[i,2],i);
end;
write(b[x2,y2]);
close(input);
close(output);
end.
вот он, венец человеческого ума - рабочий поиск в ширину без использования рекурсии, написал сам, меня очень просили запостить тут))
+97
program Project42;
{$APPTYPE CONSOLE}
uses
SysUtils, Math;
const
Radix = 10;
function čòũʼnť(N: Integer): Integer;
begin
Result := 0;
while N > 0 do
begin
N := N div Radix;
Inc(Result);
end;
end;
function count(N: Integer): Integer;
begin
// Result := Ceil(LogN(Radix, N)); { slow! }
Result := Ceil(Log10(N));
end;
function rdtsc: Int64;
asm
rdtsc
end;
var
I: Integer;
t0: Int64;
const
N = 100500;
begin
try
Assert((count(42) = čòũʼnť(42)) and (count(100500) = čòũʼnť(100500)));
t0 := rdtsc;
for I := 1 to N do
čòũʼnť(Random(MaxInt + 1));
Writeln('naïve: ', rdtsc - t0, ' ticks');
t0 := rdtsc;
for I := 1 to N do
count(Random(MaxInt + 1));
Writeln('prőper: ', rdtsc - t0, ' ticks');
Writeln(StringOfChar('-', 42));
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
if DebugHook <> 0 then
begin
Write('any big key to exit...');
Readln;
end;
end.
{ http://imgs.xkcd.com/comics/haiku_proof.png :-P }
матан > метан
O(1) > O(N)
логарифм > байтоёбства с делением
+97
Program zadacha;
var
i,chislo,x,y,m,n:integer;
begin
while i<1 do begin
for x:=0 to chislo do begin
for y:=0 to chislo do begin
for m:=0 to chislo do begin
for n:=0 to chislo do begin
if (chislo=x*x*x+y*y*y) and (chislo=m*m*m+n*n*n) and (x<>m) and (x<>y) and (y<>m) and (y<>n) then i:=1 else chislo:=chislo+1;
end;
end;
end;
end;
end;
Writeln(chislo);
end.
Вот так находят "минимальное натуральное число представимое двумя различными способами в виде суммы кубов двух натуральных чисел"
+97
procedure TStdMessageInfo.Build(pMessage: String; pKind: Integer);
var List: TStringList;
begin
List := TStringList.Create;
try {!!! это такой хитрый способ заменить #13 на #13#10}
List.Text := pMessage;
if List.Count = 1 then FMessage := List[0]
else FMessage := List.Text;
finally
List.Free;
end;
FKind := pKind;
end;
+97
{
----------------------8<----------------------
Цей юніт призначений лише для використання
разом із пакетом програм ███████
будь-якої версії.
Він не може розповсюджуватися окремо, так
як являється частиною пакету, який може
розповсюджуватися на платній основі.
(С) Copyright ███████████████
----------------------8<----------------------
}
(* ~15 строк поскипано за унылостью *)
procedure TranslateForm(var form:TObject; const LNGFile:String);
var
ini:TIniW;
c1,c2,p1,p2,i:Integer;
Sct,par,val:string;
keys:TStringList;
cobg:TObject;
comp:TComponent;
begin
initini(ini,LNGFile);
keys:=TStringList.Create;
sct:=Trim((form as TForm).Name);
c1:=ini.KeyCount(Sct);
ini.ReadSection(Sct,keys);
cobg:=(form as TObject);
for I := 0 to c1-1 do
begin
par:=keys[I];
p1:=Pos('=',par);
par:=Trim(Copy(par,0,p1-1));
val:=ini.ReadString(Sct,par,'read error');
typinfo.SetStrProp(cobg,par,val);
end;
c2:=(form as TForm).ComponentCount;
for p2 := 0 to c2 - 1 do
begin
comp:=(form as TForm).Components[p2];
cobg:=(comp as TObject);
sct:=typinfo.GetStrProp(cobg,'Name');
c1:=ini.KeyCount(Sct);
if c1>0 then
ini.ReadSection(Sct,keys);
for I := 0 to c1-1 do
begin
par:=keys[I];
p1:=Pos('=',par);
par:=Trim(Copy(par,0,p1-1));
val:=ini.ReadString(Sct,par,'read error');
try
typinfo.SetStrProp(cobg,par,val);
except
end;
end;
end;
end;
end.
Сверху - жадность, снизу - отсутствие скиллов.
+97
/// До этой строчки еще больше 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;