- 1
- 2
- 3
- 4
- 5
- 6
int size = delete.count();
for (int i = 1; i < (size + 1); i++) {
deleteDelegation(i);
i--;
if (i == 0) break;
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+84
int size = delete.count();
for (int i = 1; i < (size + 1); i++) {
deleteDelegation(i);
i--;
if (i == 0) break;
}
Задание: надо удалить все делегированные права.
+84
List selection = new ArrayList((s != null) ? s : new ArrayList());
Больше мусора для бога сборщика мусора!
+84
private static final int INT_5 = 5;
private static final int INT_3 = 3;
private static final int INT_4 = 4;
private static final int INT_6 = 6;
private static final int INT_7 = 7;
private static final int INT_8 = 8;
+84
type
TSearchF = class(TThread)
private
protected
procedure Execute; override;
public
Str: String; // думаю назначение обоих
Pause: Boolean; // параметров объяснять не надо
end;
и
Код:
procedure TSearchF.Execute;
begin
while not Terminated do
begin
if(Pause) then
begin
Sleep(10);
end else
begin
FindFile(Str);
end;
end;
end;
http://www.programmersforum.ru/showthread.php?t=91543
Без комментариев.
+84
{*********** PosEx ***********}
function Posex(const substr,str:string; const startloc:integer):integer;
{Search for "substr" in "str" starting at "startloc" return 0 or the start
postion where "substr" was found}
var
i, j,k,ssLen, sLen, stop:integer;
a:char;
begin
result:=0;
ssLen:=length(substr);
slen:=length(str);
stop:=slen-sslen+1; {highest feasible start location for substring}
if (ssLen=0) or (sslen>sLen) then exit;
a:=substr[1]; {1st letter of substr}
i:=startloc; {start search location}
while (i<=stop) and (result=0) do
begin
while (i<=stop) and (a<>str[i]) do inc(i); {find the 1st letter}
if i<=stop then
begin
if sslen=1 then result:=i {It was a 1 character search, so we're done}
else
begin
j:=2;
k:=i-1; {back "K" up by 1 so that we can use K+j as the index to the string}
while (j<=sslen) do
begin {compare the rest of the substring}
if (substr[j]<>str[k+j]) then break
else inc(j); {The letter matched, go to the next+
{When we pass the substring end, "while" loop will terminate}
end;
if (j>sslen) then
begin
result:=i;
exit;
end
else inc(i); {that search failed, look for the next 1st letter match}
end;
end;
end;
end;
Несколько вложенных циклов - это НЕ может работать быстро.
Для сравнения - функция PosEx из StrUtils.pas
function PosEx(const SubStr, S: string; Offset: Cardinal = 1): Integer;
var
I,X: Integer;
Len, LenSubStr: Integer;
begin
if Offset = 1 then
Result := Pos(SubStr, S)
else
begin
I := Offset;
LenSubStr := Length(SubStr);
Len := Length(S) - LenSubStr + 1;
while I <= Len do
begin
if S[i] = SubStr[1] then
begin
X := 1;
while (X < LenSubStr) and (S[I + X] = SubStr[X + 1]) do
Inc(X);
if (X = LenSubStr) then
begin
Result := I;
exit;
end;
end;
Inc(I);
end;
Result := 0;
end;
end;
The Delphi "Pos" function searches for a
substring within a string. Later versions of
Delphi also include a "PosEx" function
which
starts the search at a given position so
multiple calls can return all occurrences.
This program tests DFF versions of these
two
functions. Pos was rewritten to provide a
base
of code for PosEx. And PosEx wll provide
the
missing function for versions of Delphi
before
Delphi 7.
As an unexpected bonus, it appears that the
DFF versions of Pos and Posex are slightly
quicker than the D7 versions.
+84
private final public static volatile transient synchronized protected InterceptorSingletonVisitor interceptorSingletonVisitor(AbstractDecoratorStrategyProxyObserverInterceptorBuilder abstractDecoratorStrategyProxyObserverInterceptorBuilder, AbstractVisitorAdvisorFacadeListener abstractVisitorAdvisorFacadeListener, VisitorFactoryFactoryBuilder visitorFactoryFactoryBuilder, VisitorProxyFacadeFactoryFactorySingletonAdvisorDecorator visitorProxyFacadeFactoryFactorySingletonAdvisorDecorator, AbstractAdvisorBuilderDecoratorInterceptor abstractAdvisorBuilderDecoratorInterceptor) {
AbstractProxyAdvisor abstractProxyAdvisor = abstractFactoryFactoryDecorator.getListenerInterceptorFactoryFactory().getAbstractProxyAdvisor();
AbstractVisitorAdvisorListenerStrategySingletonIteratorAdapterFactory abstractVisitorAdvisorListenerStrategySingletonIteratorAdapterFactory = new AbstractVisitorAdvisorListenerStrategySingletonIteratorAdapterFactory();
abstractBeanAdvisorSingletonInterceptor.setAbstractFactoryFactoryAdvisorFacadeStrategy(this.abstractFactoryFactoryAdvisorFacadeStrategy);
AbstractAdvisorProxyStrategyIteratorVisitorObserver abstractAdvisorProxyStrategyIteratorVisitorObserver = new AbstractAdvisorProxyStrategyIteratorVisitorObserver();
if(abstractSingletonFacadeFactoryObserver.isInterceptorListenerFacade()) {
iteratorProxyListenerFacadeBean.setAbstractStrategyBean(this.abstractStrategyBean);
AbstractFactoryDecoratorBeanFacadeAdapterProxyAdvisorVisitor abstractFactoryDecoratorBeanFacadeAdapterProxyAdvisorVisitor = abstractBeanInterceptorIteratorListenerFactoryFactoryStrategyProxyObserver.getAbstractObserverFacadeListenerSingletonProxyAdvisorStrategyVisitor().getAbstractFactoryDecoratorBeanFacadeAdapterProxyAdvisorVisitor();
abstractProxyBuilderVisitorSingleton.setIteratorAdvisorProxySingletonAdapter(this.iteratorAdvisorProxySingletonAdapter);
if(abstractDecoratorAdapterVisitorProxyObserverIteratorBuilderFactory.isDecoratorFactoryFactoryFacade()) {
visitorIteratorObserverProxyAdvisor.setAbstractObserverSingletonProxyAdvisorBuilderDecorator(this.abstractObserverSingletonProxyAdvisorBuilderDecorator);
singletonFacadeAdapterListenerFactory.setAbstractIteratorInterceptorSingletonListenerAdvisorDecoratorBuilderFactoryFactory(this.abstractIteratorInterceptorSingletonListenerAdvisorDecoratorBuilderFactoryFactory);
while(abstractFactoryAdapterSingletonFactoryFactory.isAbstractStrategyFactory()) {
abstractAdapterBeanStrategySingletonAdvisorBuilderListenerFactory.setAbstractStrategyFactoryFactoryFacadeBuilderFactoryIteratorProxyObserver(this.abstractStrategyFactoryFactoryFacadeBuilderFactoryIteratorProxyObserver);
abstractObserverAdapterFactoryFacadeDecoratorBuilderInterceptorFactoryFactory.setAdvisorIteratorFactoryProxyDecorator(this.advisorIteratorFactoryProxyDecorator);
while(abstractFacadeListenerStrategyIteratorAdvisorSingletonProxyObserver.isVisitorDecoratorInterceptorIteratorAdapter()) {
abstractProxyAdapterInterceptorObserverFactoryFactoryIterator.setSingletonFactoryFactoryProxyIteratorStrategy(this.singletonFactoryFactoryProxyIteratorStrategy);
singletonInterceptorDecorator.setAbstractFactoryFactoryListenerBuilderAdvisorDecoratorFacade(this.abstractFactoryFactoryListenerBuilderAdvisorDecoratorFacade);
visitorFactoryFactoryAdapterIteratorInterceptor.setAbstractIteratorVisitor(this.abstractIteratorVisitor);
}
}
} else {
abstractListenerInterceptorStrategyVisitorBeanFactorySingletonIterator.setAbstractProxyStrategy(this.abstractProxyStrategy);
abstractProxyInterceptorSingletonFactoryFactory.setAbstractSingletonIterator(this.abstractSingletonIterator);
}
} else {
singletonListenerFactoryFactoryIteratorProxy.setAbstractObserverProxyIteratorVisitor(this.abstractObserverProxyIteratorVisitor);
}
return new InterceptorSingletonVisitor();
}
+84
// TODO: Add comment here to explain what we do
нашёл на прасторах праектуса %))
+84
function Okruglenije(cislo: Currency; skolkonulei: Integer): string;
var
outs: string;
rst, cel, zn: string;
p: integer;
begin
outs := FloatToStr(cislo);
p := Pos(',', outs) + 1;
zn := Copy(outs, p, skolkonulei);
cel := FloatToStr(trunc(cislo));
if p > 1 then
rst := Trim(cel + ',' + zn)
else
rst := Trim(cel);
Okruglenije := rst;
end;
Процедура округления
+84
uses crt;
type point=record{точки}
x,y:real;
end;
okr=record{окружности}
x,y,r:real;
end;
const nmax=20;
function Peres(a,b:point;c:okr):boolean;{пересекаются или нет}
var s,ab,h:real;
begin
s:=abs(a.x*(b.y-c.y)+b.x*(c.y-a.y)+c.x*(a.y-b.y));{удвоенная площадь треугольника
вершины которого центр окружности и 2 точки}
ab:=sqrt(sqr(a.x-b.x)+sqr(a.y-b.y));{сторона, противоположная центру окружности}
h:=s/ab;{высота на нее=расстояние от центра до прямой}
Peres:=h<c.r;{если лно меньше радиуса, пересекаются}
end;
var a:array[1..nmax] of point;
b:array[1..nmax] of okr;
n,m,i,j,k,p,mx,imx,jmx:integer;
begin
clrscr;
randomize;
repeat
write('Количество точек до ',nmax,' n=');
readln(n);
until n in [1..nmax];
repeat
write('Количество окружностей до ',nmax,' m=');
readln(m);
until m in [1..nmax];
for i:=1 to n do
begin
a[i].x:=-10+random*21;
a[i].y:=-10+random*21;
end;
for i:=1 to m do
begin
b[i].x:=-5+11*random;
b[i].y:=-5+11*random;
b[i].r:=5*random;
end;
writeln('Координаты точек:');
write('X:');
for i:=1 to n do
write(a[i].x:6:2);
writeln;
write('Y:');
for i:=1 to n do
write(a[i].y:6:2);
writeln;
writeln;
writeln('Параметры окружностей:');
write('X:');
for i:=1 to m do
write(b[i].x:6:2);
writeln;
write('Y:');
for i:=1 to m do
write(b[i].y:6:2);
writeln;
write('R:');
for i:=1 to m do
write(b[i].r:6:2);
writeln;
writeln;
mx:=0;
imx:=0;
jmx:=0;
for i:=1 to n-1 do
for j:=i+1 to n do
begin
k:=0;
for p:=1 to m do
if Peres(a[i],a[j],b[p]) then k:=k+1;
if k>mx then
begin
mx:=k;
imx:=i;
jmx:=j;
end;
end;
if mx=0 then write('Нет пересекающихся прямых и окружностей')
else
begin
writeln('Максимальное число пересечений прямой с окружностями=',mx);
write('Эта прямая проходит через точки (',a[imx].x:0:2,';',a[imx].y:0:2,') и (',a[jmx].x:0:2,';',a[jmx].y:0:2,')');
end;
readln
end.
Рекурсивная функций с циклами тройной вложенности
+84
> +
+++
+++++++
++---[>++++++
+>+++++ +++ ++>++++
+++++
++>++++++
+++++>+++++++++
+++>+++>++ +++ +++>++++++
++++>
+++++++++++
+>+++>+++++++++>+++
+++++++>++++++++++>++++++++++
+>+++><<<<<<<<<<<<<<<<-]>++>--->++>++>+>+
+>-->
+>->+
+>->+>--->++++>+++><<<<<<<<<<<<<<<<>.>.>.>.>.>.>.>.>.>.+
->.>.>.>.>.[-]++++++++++.>[-]<[>+++<-]>++.....>+++++++++
+[>+++++>+++++>+++++>+++++><<<<<-]>>-->->+><<<<<>.>.>.>.
С новым 2013м годом!
Пусть в новом году вас обойдут стороной индусизмы, баги и крестобатхерты,
а красивые решения, чистый код и годные фичи не заставят себя ждать!