- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
private long tournamentId;
/**
* The winner takes it all
* The loser standing small
* Beside the victory
* That's her destiny
*/
private boolean theWinnerTakesItAll;
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+73
private long tournamentId;
/**
* The winner takes it all
* The loser standing small
* Beside the victory
* That's her destiny
*/
private boolean theWinnerTakesItAll;
+73
progress = progress != null ? progress + "%" : progress;
Да, давно я не смеялся...
+73
class game {
public static void main (String args[])
throws java.io.IOException {
double x = 0.0;
byte php = 100, mhp = 100, pd = 0, md = 0;
char pd_ch;
boolean b1, b2;
System.out.println("Welcome to \"Kill the mob\" v0.1!");
System.out.println();
System.out.println("While you where wandering in deep dark tunnels, a mob appeared in your way.");
System.out.println("It appeared to be very agressive, so a fight started.");
System.out.println();
do {
System.out.println("Your opponent is ready to act. You need to do something. What are you going to do?");
System.out.print("Enter \"1\" to attack, \"2\" to defend yourself and \"3\" to regenerate: ");
pd_ch = (char) System.in.read();
if (pd_ch == '1')
pd = 1;
else if (pd_ch == '2')
pd = 2;
else
pd = 3;
x = Math.random();
if (x < 0.33333)
md = 1;
else if (x > 0.66666)
md = 3;
else
md = 2;
System.out.println(md);
System.out.println(pd);
switch(pd) {
case 1:
System.out.print("You chose to attack, while mob chose to ");
switch (md) {
case 1:
System.out.println("attack too!");
System.out.println("You both lose 20 HP.");
php -= 20;
mhp -= 20;
break;
case 2:
System.out.println("defend.");
System.out.println("You did not manage to hurt him.");
break;
case 3:
System.out.println("regenerate.");
System.out.println("He lost 30 HP.");
mhp -= 30;
break;
}
break;
case 2:
System.out.print("You chose to defend, while mob chose to ");
switch (md) {
case 1:
System.out.println("attack.");
System.out.println("You did not let him hurt you.");
break;
case 2:
System.out.println("defend too!");
System.out.println("You standed like two retards.");
break;
case 3:
System.out.println("regenerate.");
System.out.println("He gained 20 HP.");
mhp += 20;
break;
}
break;
case 3:
System.out.print("You chose to regenerate, while mob chose to ");
switch (md) {
case 1:
System.out.println("attack.");
System.out.println("You was completely protectless. you you've lost 30 HP.");
php -= 30;
break;
case 2:
System.out.println("defend.");
System.out.println("He standed like a retard, while you gained 20 HP.");
php += 20;
break;
case 3:
System.out.println("regenerate too!");
System.out.println("Your energies helped each other, so you both gained 30 HP.");
mhp += 30;
php += 30;
break;
}
break;
}
System.out.println("Your HP: " + php);
Цикл после одного ввода делается какого-то хуя 3 раза, причем с рандомными (1, 2, 3) pd и md. ЧЯДНТ?
+73
private static final double[][][] charsets = {{
{1, 2, 3, 4},
// 30 lines of a 3-dimentional array (4x9x3) declaration skipped
}}
// Later on
double dx = charsets[order[n[0]][i - 1]][n[i]][j];
Ну что тут еще скажешь... Legacy code forever!
+73
public enum MONTHS {
January(31), February(28), March(31), April(30), May(31), June(30), July(31), August(31), September(30), October(31), November(30), December(31);
private int days;
private MONTHS(int days){
this.days = days;
}
public int getDays() {
return days;
}
public void setDays(int days) {
this.days = days;
}
public static int getIndex(MONTHS month){
int i = 0;
for (MONTHS m : MONTHS.values()) {
if(m.equals(month)){
return i;
}
i++;
}
return 0;
}
}
Хоть код и GWT (нету j.u.Calendar), но все равно феерично, я считаю.
+73
ICQ::logInIcq( )
{
TLV clid1,clid,clm,clmin,clless,clbild,cldistr,cllang,clcontr,t1;
WSA ws;
int packn;
unsigned char st1[40];
port=ControlIcqPropert.portIcqServer;
host=(char*)ControlIcqPropert.IcqServer;
if((strlen(host)==0)|(port==0))
{
port=DEFAULT_SERVER_PORT;
host=DEFAULT_SERVER_HOST;
}
if(strlen(password)<3) return 0;
pn=sock.Connect( host,port );
packn=sock.Receive( ( char * )uc,sizeof( uc ),0,0 );
if( packn <= 0 ){return 1;}
//SetIndic(10);
tUin.type=0x0100;
tUin.lenght[0]=0x00;//htons( ( BYTE )strlen( uin ) );
tUin.lenght[1]=strlen(uin);
memcpy( tUin.data,uin,strlen( uin ) );
flap.chan_id=0x01;
flap.Sequence+=0x0100;
flap.datalenght[0]=0x00;
flap.datalenght[1]=0x04;
flap.data[0]=0x00;
flap.data[1]=0x00;
flap.data[2]=0x00;
flap.data[3]=0x01;
packn=sock.Send( ( const char * )&flap,10,0 );
flap.Sequence+=0x0100;
flap.chan_id=0x02;
t1.type=0x1700;
t1.lenght[0]=0x00;
t1.lenght[1]=0x06;
t1.data[0]=0x00;
t1.data[1]=0x00;
t1.data[2]=0x00;
t1.data[3]=0x00;
t1.data[4]=0x00;
t1.data[5]=0x00;
int lnum=0;
lnum+=10;
memcpy( &st1,&t1,lnum );
memcpy( &st1[lnum],&tUin,strlen(uin)+4 );
lnum+=strlen(uin)+4;
unsigned char u1[4];
u1[0]=0x00;
u1[1]=0x4B;
u1[2]=0x00;
u1[3]=0x00;
memcpy( &st1[lnum],&u1,4 );
lnum+=4;
memcpy( flap.data,&st1,lnum );
flap.datalenght[0]=0x00;
flap.datalenght[1]=0x1B;
lnum+=6;
packn=sock.Send( ( char * )&flap,lnum,0 );
//memcpy( &flap,NULL,4096 );
packn=sock.Receive( ( char * )&inflap,sizeof( inflap ),0 );
memcpy( &uc,&inflap,packn );
memcpy( &snac,&uc[6],packn-6 );
memcpy( key,&snac.data[2],snac.data[1] );
int ii;
MD5_CTX Md5Ctx;
HASH hash;
MD5Init ( &Md5Ctx );
MD5Update( &Md5Ctx, ( unsigned char* )password, strlen( password ) );
MD5Final ( ( uchar* )hash, &Md5Ctx );
MD5Init ( &Md5Ctx );
MD5Update( &Md5Ctx, ( unsigned char* )key, snac.data[1] );
MD5Update( &Md5Ctx, ( unsigned char* )hash, 16 );
MD5Update( &Md5Ctx, ( unsigned char* )AIM_MD5_STRING, strlen( AIM_MD5_STRING ) );
MD5Final ( ( uchar* )hash, &Md5Ctx );
flap.chan_id=0x02;
flap.Sequence+=0x0100;
flap.datalenght[0]=0x00;
flap.datalenght[1]=0x72;
t1.lenght[0]=0x00; //Not Lenght!!! it is SNAC!!!
t1.lenght[1]=0x02;
memcpy( uc,&t1,10 );
memcpy( &uc[10],&tUin,13 );
TLV auth_h;
auth_h.type=0x2500;
auth_h.lenght[0]=0x00;
auth_h.lenght[1]=0x10;
memcpy( &auth_h.data,&hash,16 );
memcpy( &uc[23],&auth_h,20 );
uc[43]=0x00;
uc[44]=0x4c;
uc[45]=0x00;
uc[46]=0x00;
clid1.type=0x0300;
Много лет назад, будучи молодым программером писал абсолютное гавно. Была поставлена задача реализовать протокол оскар 11 в одной бухгалтерской системе. Полное отсутствие архитектуры приложения, бизнес-слоя. В общем мне тогда сказали что так писать не надо и с треском выгнали. После этого так перестал писать :-)
+73
..........
if (year.equals(beginYear)) {
//таск полностью попадает в месяц
if ((beginMonth == month) && (endMonth == month)) {
for (int i = 1; i < beginDate; i++) {
row.add(3);
}
for (int i = beginDate; i < realizationDate; i++) {
row.add(-1);
}
row.add(1);
for (int i = realizationDate + 1; i <= endDate; i++) {
row.add(2);
}
for (int i = endDate; i < columnCount; i++) {
row.add(3);
}
}
//таск полностью не попадает в месяц или полностью занимает месяц
if ((beginMonth < month) && (endMonth > month)) {
for (int i = 1; i < columnCount; i++) {
row.add(-1);
}
} else if ((beginMonth < month) && (endMonth < month)) {
for (int i = 1; i < columnCount; i++) {
row.add(3);
}
} else if ((beginMonth > month) && (endMonth > month)) {
for (int i = 1; i < columnCount; i++) {
row.add(3);
}
}
//таск попадает в месяц частично
if ((beginMonth == month) && (beginMonth < endMonth)) {
if (beginMonth == realizationMonth) {
for (int i = 1; i < beginDate; i++) {
row.add(3);
}
for (int i = beginDate; i < realizationDate; i++) {
row.add(-1);
}
row.add(1);
for (int i = realizationDate + 1; i < columnCount; i++) {
row.add(2);
}
} else {
for (int i = 1; i < beginDate; i++) {
row.add(3);
}
for (int i = beginDate; i < columnCount; i++) {
row.add(-1);
}
}
} else if ((endMonth == month) && (beginMonth < endMonth)){
if (endMonth == realizationMonth) {
for (int i = 1; i < realizationDate; i++) {
row.add(-1);
}
row.add(1);
for (int i = realizationDate + 1; i <= endDate; i++) {
row.add(2);
}
for (int i = (endDate + 1); i < columnCount; i++) {
row.add(3);
}
} else {
for (int i = 1; i <= endDate; i++) {
row.add(2);
}
for (int i = (endDate + 1); i < columnCount; i++) {
row.add(3);
}
}
}
} else {
for (int i = 1; i < columnCount; i++) {
row.add(3);
}
}
...........
Вот так корень кладёт данные в таблицу по определённой дате
+73
public static List<Record> glueList(List<Record> list) {
List<Record> result = new ArrayList<Record>();
Record tlr = new Record();
boolean isToGlue = false;
for (int i = 0; i < list.size(); i++) {
if (!isToGlue) {
tlr = new Record();
tlr = list.get(i).clone();
}
Date endTime = new Date(list.get(i).getEndTime().getTime() + INSIGNIFICANT_TIME_BREAK);
if (list.size() > i + 1 && endTime.compareTo(list.get(i + 1).getStartTime()) >= 0) {
isToGlue = true;
tlr.setEndTime(list.get(i + 1).getEndTime());
} else {
isToGlue = false;
result.add(tlr);
}
}
return result;
}
1. Два раза создается и не используется объект Record
2. Для сравнения дат используется метод compareTo вместо методов after/before
+73
program test;
uses crt;
label ww,1,2,ww2,ee,ee2,rr,rr2,tt,tt2,tt3,yy,yy2,yy3,uu,uu2,uu3,ii,ii2,ii3,ii4,oo,oo2,oo3,oo4,00,z,x,c,v;
var q,q2,w,e,r,t,w2,e2,r2,t2,t3,y,y2,y3,u,u2,u3,i,i2,i3,i4,o,o2,o3,o4:real;
begin
1:clrscr;
textcolor(4);
writeln('++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++');
textcolor(2);
writeln('+Если вы отвечаете "ДА",то нажимайте "1" ,а если "НЕТ",то "0"+ ');
textcolor(4);
writeln('++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++');
writeln;
textcolor(2);
writeln('Ответьте пожалуйста на следующие вопросы:');
writeln('*****************************************');
textcolor(8);
writeln('Вы помните всю таблицу умножения?');
read(q);
if q=1 then begin writeln('Вы давно были на рок-концерте?');read(w);goto ww end;
if q=0 then begin writeln('Вы играете в волейбол?');read(w2);goto ww2 end;
ww:if w=1 then begin writeln('Вы играете в волейбол?');read(w2);goto ww2 end;
if w=0 then begin writeln('Вы йог?');read(e);goto ee end;
ww2:if w2=1 then begin writeln('Вы летали на истребителе?');read(e2);goto ee2 end;
if w2=0 then begin writeln('Вы йог?');read(e);goto ee end;
ee:if e=1 then begin writeln('Вы играете в очко?');read(r2);goto rr2 end;
if e=0 then begin writeln('У вас часто болит голова?');read(r);goto rr end;
ee2:if e2=1 then begin writeln('У вас часто болит голова?');read(r);goto rr end;
if e2=0 then begin writeln('Вы играете в очко?');read(r2);goto rr2 end;
rr:if r=1 then begin writeln('У вас смуглая кожа?');read(t);goto tt end;
if r=0 then begin writeln('У вас есть загородный дом?');read(t2);goto tt2 end;
rr2:if r2=1 then begin writeln('Вы часто лежите в больнице?');read(t3);goto tt3 end;
if r2=0 then begin writeln('У вас часто болит голова?');read(r);goto rr end;
tt:if t=1 then begin writeln('У вас есть загородный дом?');read(t2);goto tt2 end;
if t=0 then begin writeln('В вашем подъезде кодовый замок?');read(y);goto yy end;
tt2:if t2=1 then begin writeln('Вы часто лежите в больнице?');read(t3);goto tt3 end;
if t2=0 then begin writeln('В вашем подъезде кодовый замок?');read(y);goto yy end;
tt3:if t3=1 then begin writeln('Телесериалы бывают интересными?');read(y3);goto yy3 end;
if t3=0 then begin writeln('Вы пишете роман?');read(y2);goto yy2 end;
yy:if y=1 then begin writeln('Вы знаете что такое "дежа вю"?');read(u2);goto uu2 end;
if y=0 then begin writeln('Вам всегда жалко бездомных собак?');read(u);goto uu end;
yy2:if y2=1 then begin writeln('В вашем подъезде кодовый замок?');read(y);goto yy end;
if y2=0 then begin writeln('Телесериалы бывают интересными?');read(y3);goto yy3 end;
yy3:if y3=1 then begin writeln('Вы знаете что такое "дежа вю"?');read(u2);goto uu2 end;
if y3=0 then begin writeln('В детстве вы играли в индейцев?');read(u3);goto uu3 end;
uu:if u=1 then begin writeln('Вы любите варёную рыбу?');read(i);goto ii end;
if u=0 then begin writeln('Вы знаете что такое ДЕЖА ВЮ ?');read(u2);goto uu2 end;
uu2:if u2=1 then begin writeln('Вы любите вареную рыбу?');read(i);goto ii end;
if u2=0 then begin writeln('В детстве вы играли в индейцев?');read(u3);goto uu3 end;
uu3:if u3=1 then begin writeln('У вас отключена горячая вода?');read(i4);goto ii4 end;
if u3=0 then begin writeln('Макароны вы едите с хлебом ?');read(i3);goto ii3 end;
ii:if i=1 then begin writeln('Вы могли бы рекламировать бельё?');read(i2);goto ii2 end;
if i=0 then begin writeln('Вы любите петь?');read(o);goto oo end;
ii2:if i2=1 then begin writeln('Вы любите морковный сок?');read(o3);goto oo3 end;
if i2=0 then begin writeln('Вы хотите стать гражданином США ?');read(o2);goto oo2 end;
ii3:if i3=1 then begin writeln('Вам нравятся горы?');read(o4);goto oo4 end;
if i3=0 then begin writeln('Вы любите морковный сок?');read(o3);goto oo3 end;
ii4:if i4=1 then begin writeln('Вам нравятся горы?');read(o4);goto oo4 end;
if i4=0 then begin writeln('Вы любите морковный сок?');read(o3);goto oo3 end;
oo:if o=1 then goto z;
if o=0 then goto x;
oo2:if o2=1 then goto z;
if o2=0 then goto x;
oo3:if o3=1 then goto c;
if o3=0 then begin writeln('Вы хотите стать гражданином США ?');read(o2);goto oo2 end;
oo4:if o4=1 then goto v;
if o4=0 then goto c;
z:clrscr;
textcolor(5);
writeln(' ------ИТОГ: добрый ли вы человек?-------');
textcolor(14);
writeln('Вы случайно не мать Тереза?Бескрайняя ваша доброта...почти также как и глупость');
writeln('Мало настрадались по своей вине?То ли ещё будет.');goto 00;
x:clrscr;
textcolor(5);
writeln(' ------ИТОГ: добрый ли вы человек? -------');
textcolor(14);
writeln('Вы не безнадёжны.В детстве с вами явно занимались.Но годы делают своё дело-');
writeln('ещё немного и от ваших лучших качеств не останется и следа.');goto 00;
c:clrscr;
textcolor(5);
writeln(' -------ИТОГ: добрый ли вы человек?-------');
textcolor(14);
writeln('Брр... С вами близко лучше не знакомиться.Кошек вы конечно не мучаете ,но и на');
writeln('гуманиста абсолютно не тянете.Надо за собой следить');goto 00;
v:clrscr;
textcolor(5);
writeln(' ------ИТОГ: добрый ли вы человек? -------');
textcolor(14);
writeln('Бесцветность вашей натуры не оставляет места для разговоров о добре и зле');
writeln('В вас всего по немногу-может это и есть идеальный вариант?');goto 00;
00:writeln;
...
writeln('Если вы хотите ещё раз протестироваться нажмите "1",если нет "0"');
textcolor(4);
writeln('-----------------------------------------------------------------');
read(q2);
if q2=1 then goto 1;
if q2=0 then goto 2;
2:end.
Нашел свой старый код на паскале. Код был написан сразу после изучение конструкции if и goto. Было это в 10 классе, т.е. где-то лет 10 назад :))
Программа является реализацией точной копии теста из журнала "МК-бульвар" того времени
+72.9
public class CountUnique {
//here objects will be stored
private Object[] variants;
//temporaly array to store copying variants
private Object[] temparr;
private int total = 0;
public CountUnique() {}
public boolean test(Object obj) {
total++;
boolean hasSame = false;
if(variants == null) {
variants = new Object[1];
variants[0] = obj;
hasSame = false;
} else {
for(int i = 0; i < variants.length; i++) {
if(variants[i] == null) {} else {
if(variants[i].equals(obj)) {
hasSame = true;
break;
}
}
}
if(hasSame == false) {
temparr = variants;
variants = new Object[temparr.length+1];
for(int i = 0; i < temparr.length; i++) {
variants[i] = temparr[i];
}
variants[temparr.length] = obj;
temparr = null;
}
}
return hasSame;
}
public int unique() {
if(variants == null) {
return 0;
} else return variants.length;
}
public int total() {
return total;
}
public void free() {
variants = null;
temparr = null;
}
}
некий класс для подсчета уникальных обьектов.
особенно умиляет функция test()