1. Лучший говнокод

    В номинации:
    За время:
  2. Java / Говнокод #15990

    +69

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    94. 94
    95. 95
    package com.javarush.test.level06.lesson11.bonus02;
     
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
     
    /* Нужно добавить в программу новую функциональность
    Задача: У каждой кошки есть имя и кошка-мама. Создать класс, который бы описывал данную ситуацию. Создать два объекта: кошку-дочь и кошку-маму. Вывести их на экран.
    Новая задача: У каждой кошки есть имя, кошка-папа и кошка-мама. Изменить класс Cat так, чтобы он мог описать данную ситуацию.
    Создать 6 объектов: маму, папу, сына, дочь, бабушку(мамина мама) и дедушку(папин папа).
    Вывести их всех на экран в порядке: дедушка, бабушка, папа, мама, сын, дочь.
     
    Пример ввода:
    дедушка Вася
    бабушка Мурка
    папа Котофей
    мама Василиса
    сын Мурчик
    дочь Пушинка
     
    Пример вывода:
    Cat name is дедушка Вася, no mother, no father
    Cat name is бабушка Мурка, no mother, no father
    Cat name is папа Котофей, no mother, father is дедушка Вася
    Cat name is мама Василиса, mother is бабушка Мурка, no father
    Cat name is сын Мурчик, mother is мама Василиса, father is папа Котофей
    Cat name is дочь Пушинка, mother is мама Василиса, father is папа Котофей
    */
     
    public class Solution
    {
        public static void main(String[] args) throws IOException
        {
            BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
     
            String grfatherName = reader.readLine();
            Cat catGrfather = new Cat(grfatherName);
     
            String grmotherName = reader.readLine();
            Cat catGrmother = new Cat(grmotherName);
     
            String fatherName = reader.readLine();
            Cat catFather = new Cat(fatherName, catGrfather, null);
     
            String motherName = reader.readLine();
            Cat catMother = new Cat(motherName, null, catGrmother);
     
            String sonName = reader.readLine();
            Cat catSon = new Cat(sonName, catFather, catMother);
     
            String daughterName = reader.readLine();
            Cat catDaughter = new Cat(daughterName, catFather, catMother);
     
            System.out.println(catGrfather);
            System.out.println(catGrmother);
            System.out.println(catFather);
            System.out.println(catMother);
            System.out.println(catSon);
            System.out.println(catDaughter);
     
        }
     
        public static class Cat
        {
            private String name;
            private Cat father;
            private Cat mother;
     
     
            Cat(String name)
            {
                this.name = name;
            }
     
            Cat (String name, Cat father, Cat mother){
                this.name = name;
                this.mother = mother;
                this.father = father;
     
            }
     
            @Override
            public String toString()
            {
                if ((mother == null) && (father == null))
                    return "Cat name is " + name + ", no mother, no father ";
                else if (father == null)
                    return "Cat name is " + name + ", mother is " + mother.name + " , no father";
                else if (mother == null)
                    return  "Cat name is " + name + ", no mather " + ", father is " + father.name;
                else
                    return "Cat name is " + name + ", mother is " + mother.name + ", father is " + father.name;
            }
        }
    }

    Да лаба, точнее задание. Но меня так умиляет решение задачи :) Просто немного хардкода :)

    kostoprav, 15 Мая 2014

    Комментарии (6)
  3. Java / Говнокод #15972

    +73

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    public static int getWordCount(String getInput, int e){
        int numberOfWords = 0;
        char l1 = 0;
        char l2 = 0;
        StringBuilder convertInput = new StringBuilder(getInput);
        System.out.println(convertInput);
        for (int i = 0, i1 = 1; i < getInput.length();i++, i1++){
            l2 = convertInput.charAt(i);
            if (l2 == ' '){
                numberOfWords += 1;
                l1 = convertInput.charAt(i1);
            }
            if (i == getInput.length() - 1){
                numberOfWords += 1;
            }
            if (l2 == ' ' && l1 == ' '){
                numberOfWords -= 1;
            }
        }
        return numberOfWords;
     } // end of getWordCount method

    http://docs.oracle.com/javase/7/docs/api/java/util/StringTokenizer.html да и просто регексп на крайняк как видно запрещены религией.

    kostoprav, 13 Мая 2014

    Комментарии (6)
  4. JavaScript / Говнокод #15969

    +157

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    function test(x) {
        function undefined(x) { throw "Missing in action"; }
        switch (x) {
        case 1: console.log("X reporting for duty!"); break;
        case undefined(x): break;
        }
    }

    Переделка длинного и скучного кода, но смысл остался.

    wvxvw, 13 Мая 2014

    Комментарии (6)
  5. Java / Говнокод #15942

    +75

    1. 1
    return new Integer(((Integer)var).intValue()+1);

    Autoboxing? Не, не слышал...

    kostoprav, 08 Мая 2014

    Комментарии (6)
  6. C++ / Говнокод #15885

    +17

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    cKeyCfg::types_t cConfiguration::SearchInType(string type)
    {
        CTint i = 0;
        const CTbyte * types[] = { "S", "D" };
    
        for(i = 0; i < sizeof(types)/sizeof(types[0]); i++) {
          if ( strcmp(type.c_str(),types[i]) == 0) {
            switch (i) {
            case 0: // Is string
              return cKeyCfg::stringa;
            case 1: // Is decimal
              return cKeyCfg::decimale;
            default: //Default value VT_BSTR
              return cKeyCfg::unknow;
            }
          }
        }
        return cKeyCfg::unknow;
    }

    сделано на родине Fiat'а.

    Dummy00001, 02 Мая 2014

    Комментарии (6)
  7. Си / Говнокод #15871

    +134

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    try{
        tempPage1Int = tempPage1.ToInt();
      }catch(Exception &E){
        tempPage1Int = 0;
        goto NEXTFUCKER;
      }
      NEXTFUCKER:

    Дописываю из-под стола.

    dm-ua, 30 Апреля 2014

    Комментарии (6)
  8. Java / Говнокод #15810

    +70

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    {
    	final int p = page;
    	final boolean current = p == 1;
    	this.pagercell(writer, current, 1, "<<");
    }
    for (int p = page - this.size; p < page; p++) {
    	if (p >= 1) {
    		final boolean current = p == 1;
    		this.pagercell(writer, current, p);
    	}
    }
    {
    	final int p = page;
    	final boolean current = (p - this.size) < 1;
    	this.pagercell(writer, current, p - this.size, "<");
    }
    {
    	final int p = page;
    	final boolean current = p == page;
    	this.pagercell(writer, current, p);
    }
    {
    	final int p = page;
    	final boolean current = (p + this.size) > pages;
    	this.pagercell(writer, current, p + this.size, ">");
    }
    for (int p = page + 1; p <= (page + this.size); p++) {
    	if (p <= pages) {
    		final boolean current = p == pages;
    		this.pagercell(writer, current, p);
    	}
    }
    {
    	final int p = page;
    	final boolean current = p == pages;
    	this.pagercell(writer, current, pages, ">>");
    }

    веселый вывод постраничной навигации (кусок метода)

    Lure Of Chaos, 22 Апреля 2014

    Комментарии (6)
  9. Pascal / Говнокод #15803

    +81

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    procedure SetCurrentThreadName(const AName: String);
    type
      TThreadNameInfo = record
          RecType: LongWord;
          Name: PChar;
          ThreadID: LongWord;
          Flags: LongWord;
        end;
    var
      LThreadNameInfo: TThreadNameInfo;
    begin
      with LThreadNameInfo do
      begin
        RecType := $1000;
        Name := PChar(AName);
        ThreadID := $FFFFFFFF; // -1 - текущий поток; также сюда можно вставить ID другого потока
        Flags := 0;
      end;
      try
        RaiseException($406D1388, 0, SizeOf(LThreadNameInfo) div SizeOf(LongWord),
          PDWord(@LThreadNameInfo));
      except
      end;
    end;

    Попытка создать именованный поток.
    Не хак. (http://msdn.microsoft.com/en-us/library/xcb2z8hs%28VS.71%29.aspx)

    brutushafens, 20 Апреля 2014

    Комментарии (6)
  10. Куча / Говнокод #15796

    +143

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    Lol1 = "1", Lol2 = "2"
    set lols = array
    lols.append Lol1
    lols.append Lol2
    set result = string
    result = lols.foldl1 (++)
    Put result

    Название языка ещё не придумал :)

    Mobac, 20 Апреля 2014

    Комментарии (6)
  11. Куча / Говнокод #15738

    +125

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    % -*- mode: Prolog -*-
    
    :- module e9.
    :- interface.
    :- import_module io.
    :- pred main(io::di, io::uo) is cc_multi.
    
    :- implementation.
    :- import_module int, float, list, string, math.
    
    :- func root(int) = int.
    root(Number) = floor_to_int(sqrt(float(Number))).
    
    :- func squares_under(int, int) = list(int).
    squares_under(From, To) = Result:-
        (Square = From * From,
         (if Square =< To
         then Result = [Square | squares_under(From + 1, To)]
         else Result = [])).
    
    :- pred list_to_disjunction(list(int)::in, int::out) is nondet.
    list_to_disjunction([Head | Tail], Result):-
        (Result = Head; list_to_disjunction(Tail, Result)).
    
    :- pred summands_of(list(int)::in, int::in, { int, int, int }::out) is cc_nondet.
    summands_of(Squares, Sum, { A, B, C }):-
        list_to_disjunction(Squares, As),
        list_to_disjunction(Squares, Bs),
        list_to_disjunction(Squares, Cs),
        As < Bs, Bs < Cs,
        As + Bs = Cs,
        root(As) + root(Bs) + root(Cs) = Sum,
        A = As, B = Bs, C = Cs.
    
    main(!IO):-
        Sum = 1000,
        Squares = squares_under(1, Sum * Sum),
        (if summands_of(Squares, Sum, { A, B, C })
        then io.format("Answer: A = %d, B = %d, C = %d\n", [i(A), i(B), i(C)], !IO)
        else io.format("No solutions\n", [], !IO)).

    Давно как-то мы не вспоминали Прожект Ойлер.
    Язык: Меркури,
    Эффективность решения: наверное, полный пиздец.

    Для тех, кому нечем заняться: http://joyreactor.com/post/954661

    wvxvw, 12 Апреля 2014

    Комментарии (6)