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

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

    +4

    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
    int DataBase::garbageCollector(string filename){ 
        fstream from(filename.c_str());
        fstream from0((filename+".index").c_str());
        Index x;
        Data d;
        char *a/*,*b*/;
        int oldpos = 0 ;
        bool done = false;
        from.seekg(0,ios::end);
        int dbend = static_cast<int>(from.tellp());
        from0.seekg(0,ios::end);
        int indexend = static_cast<int>(from0.tellp());
        if(dbend == BlockSize || indexend == IndexSize){
    	from.close();
    	from0.close();
    	return 0;
        }
        from.seekg(0,ios::beg);
        from0.seekg(0,ios::beg);
        while(true){ 
            from0 >> x;
            if(from0.eof())break;
            if(!x.Num()){ 
                int count = dbend - x.Pointer() - BlockSize;
                int count0 = indexend - (static_cast<int>(from0.tellp())+1);
                from.seekg(x.Pointer()+BlockSize);
                a = new char[count]; 
                from.read(a,count);
                from.seekp(x.Pointer());
                from.write(a,count);
                delete a;
                a = new char[count0];
                from0.seekp(1,ios::cur);
                int test = from0.tellp();
                from0.read(a,count0);
                from0.clear();
                from0.seekp(indexend - count0 - IndexSize,ios::beg);
                test = from0.tellp();
                from0.write(a,count0);
                test = from0.tellp();
                delete a;
                ofstream to("tmp.base",ios::trunc),to0("tmp.index",ios::trunc);
                a = new char[dbend - BlockSize];
                from.seekg(0,ios::beg);
                from.read(a,dbend - BlockSize);
                to.write(a,dbend - BlockSize);
                delete a;
                a = new char[indexend - IndexSize];
                from0.seekg(0,ios::beg);
                test = from0.tellp();
                from0.read(a,indexend - IndexSize);
                to0.write(a,indexend - IndexSize);
                delete a;
                from.close();
                from0.close();
                if(remove(filename.c_str()) || rename("tmp.base",filename.c_str())) return -1;
                if(remove((filename+".index").c_str()) || rename("tmp.index",(filename+".index").c_str())) return -1;
                oldpos = indexend - count0 - IndexSize;
                done = true;
                break;
            }
        }
        if(done){
            from0.open((filename+".index").c_str());
            while(true){ 
                from0 >> x;
                if(from0.eof())break;
                if(x.Pointer() > static_cast<unsigned>((oldpos/23)*BlockSize) ){ 
                    x.Pointer(x.Pointer()-BlockSize);
                    from0.seekp(-(IndexSize-1),ios::cur);
                    from0 << x;
                    int test = from0.tellp();
                }
                else{ 
                    from0.seekp(-(IndexSize-1),ios::cur);
                    from0 << x;
                    int test = from0.tellp();
                    from0.clear();
                }
            }
        }
        return 0;
    }

    Собираем пустые блоки

    Abbath, 15 Октября 2013

    Комментарии (14)
  3. C# / Говнокод #13861

    +127

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    <Grid x:Name="LayoutRoot" >
    	<Grid.ColumnDefinitions>
    		<ColumnDefinition />
    	</Grid.ColumnDefinitions>
    	<Grid.RowDefinitions>
    		<RowDefinition />
    	</Grid.RowDefinitions>
    	
    	// .. разные контролы
    	
    </Grid>

    Это тоже кусочек XAML (WPF)

    Smekalisty, 27 Сентября 2013

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

    +141

    1. 1
    for (; b < d; b++)

    subj

    Stealth, 23 Августа 2013

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

    +6

    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
    #include <iostream>
    
    using std::cout;
    using std::endl;
    
    auto power(double x, int n)-> double*;
    
    int main()
    {
    	void * c = power(5,2);
    
    	std::cout << *(double*)c << std::endl;
    
    	return 0;
    }
    
    auto power(double x, int n)-> double* 
    { 
    	double* result(new double(1.0));
    	for(int i = 1; i <= n; i++)
    	*result *= x;
    	return result;
    }

    taburetka, 21 Августа 2013

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

    +5

    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
    #include <iostream>
     
    using namespace std;
     
    void f(void){cout<<"f"<<endl;}
    void f1(void){cout<<"f1"<<endl;}
     
    bool secondIfIsTryed(){cout<<"secondIfIsTryed"<<endl;return true;}
     
    #define asserts(Condition) {cout<<"Assert"<<endl;}
     
    int main() {
        if(true)
            if(secondIfIsTryed() && false)
                f();
            else
                f1();
        
        if(true)
            if(secondIfIsTryed() && false)
                asserts(true)
            else
                f1();
        return 0;
    }

    Помните того вечно сомневающегося знакомого, тест крестов, написанный которым я недавно приводил?
    http://ideone.com/9Q61D1
    В этот раз под его глуповатый, но пытливый взгляд попал макрос ассерта. Написан он конечно не так, как в этом тесте, но имеет код вида:

    #define asserts(Condition) {/*...*/}


    В итоге он сделал умозаключение: "Вокруг меня собрались голубцы" и надулся.

    LispGovno, 19 Июля 2013

    Комментарии (14)
  7. Куча / Говнокод #13423

    +125

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    wrs(S):-put_char('\"'), wrsi(S).
    wrsi([C|S]):-put_char(C), wrsi(S).
    wrsi([]):-put_char('\"').
     
    wrl(S):-put_char('['), wrli(S), put_char(']').
    wrli([C|[O|S]]):-wrs(C), put_char(','), wrli([O|S]).
    wrli([C]):-wrs(C).
     
    :- wrl(["dog", "cat", "canary"]).

    Курю правильные примеры кода на прологе. PrologGovno ждите во всех кинотеатрах страны.
    http://ideone.com/L4vIKs
    Почему вместо того чтобы пользоваться стандартной функцией вывода списков или строк - автор рекомендует это? Я код правда поправил, а то хаскельных скобок (я уже без них не могу) не было и запятую в конце списка выдавало.

    HaskellGovno, 15 Июля 2013

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

    +15

    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
    #include<iostream>
    #include<set>
    #include<vector>
    #include<hash_set>
    #include<math.h>
    #include<stdlib.h>
    using namespace std;
    inline int po(int a,int b){
    int ans =1;
    for(int i=0;i<b;++i)ans*=a;
    return ans;
    }
    inline bool isnotsq(int a){
    	return sqrt(0.0+a)!=int(sqrt(a+0.0));
    }
    
    int main(){
    	int t,n,k;
    	cin>>t;
    	int SQRT  = 100000,primes[100100]={0};
    	primes[2]=1;
    	vector<int> pr;
    	pr.push_back(2);
    	for(int i = 3;i<=SQRT;i+=2){
    		if(primes[i]==0) {
    			pr.push_back(i);
    			for(int j = 2*i;j<=SQRT;j+=i) primes[j]=1;
    		}
    	}
    	while(t--){
    		cin>>n>>k;
    		int nn=n;
    		int divisors[1001];
    		int divisecount[1001]={0};
    		int divc=0;
    		int count = 0;
    		for(int i =0;i<pr.size();++i){
    			if(n%pr[i]==0) divisors[divc++]=pr[i];
    			while(n%pr[i]==0) divisecount[divc-1]++,n/=pr[i],count++;
    		}
    		if(n!=1) divisors[divc++]=n,divisecount[divc-1]=1;
    		//for(int i =0;i<divc;++i) cout<<divisors[i]<<' '<<divisecount[i]<<'\n';
    		vector< int> cbused;
    		vector<int> rem;
    		rem.push_back(0);
    		cbused.push_back(1);
    		
    		for(int i =0;i<divc;++i){
    			int cs = cbused.size();
    			for(int j =0;j<cs;++j){
    				int cc = divisors[i];
    				int ops=1;
    				while(1){
    					if(nn%(cbused[j]*cc)==0) {
    						if(isnotsq(cbused[j]*cc)) 
    							cbused.push_back(cbused[j]*cc),rem.push_back(rem[j]+ops);
    					}
    					else break;
    					cc*=divisors[i];
    					ops+=1;
    				}
     			}
    		}
    		//for(int  i = 0;i<cbused.size();++i) cout<<cbused[i]<<' '<<rem[i]<<'\n';
    		int siz= cbused.size();
    		set< pair<int,int > > anse;
    		anse.insert(make_pair(1,0));
    		for(int j = 1;j<siz;++j){
    			for(int i = cbused[j],k=1;nn%i==0;i*=cbused[j],k++) if(i%2==1) anse.insert(make_pair(i,k));
    		}
    		for(int i = 1;i<siz;++i){
    				vector<pair<int , int> > toa;
    				for(set< pair<int,int> >::iterator it=anse.begin();it!=anse.end();it++){
    					if(nn%(cbused[i]*it->first)==0&&it->second<k) toa.push_back(make_pair(cbused[i]*it->first,it->second+1));
    					for(int q=0;q<toa.size();q++) anse.insert(toa[q]);
    				}
    			}
    		
    		bool f = false;
    		for(set< pair<int,int> >::iterator it=anse.begin();it!=anse.end();it++){
    			if(it->first==nn&&it->second==k) f=true;
    		}
    		cout<<(f?"YES":"NO")<<"\n";
    		if(t==0) return 0;
    	}
    }

    Задано целое положительное число n. Выясните, может ли оно быть представлено в виде произведения k целых положительных чисел, ни одно из которых не является квадратом целого числа.
    (с яндекс.алгоритма)

    AvadaKedavra, 14 Июля 2013

    Комментарии (14)
  9. JavaScript / Говнокод #13288

    +155

    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
    /* Декодирование параметров
    ===========================================================================*/
    $(document).ready(function () {
        var stext = $("input[name = 'stext'], input[name = 'text']");
    
        function decodeURLParameter(name) {
            if (!!name) return decodeURI((RegExp(name + '=' + '(.+?)(&|$)').exec(location.search) || [, null])[1]);
        }
    
        if (stext) {
            var urlText = decodeURLParameter('stext');
            if (urlText != undefined && urlText != "" && urlText[0] != '&' && urlText != "null") {
                var sstext = [stext[1], stext[2]];
    
                $(sstext).val(urlText);
            }
        }
    });

    Будучи младшим веб-разработчиком наваял...

    sladkijBubaleh, 02 Июля 2013

    Комментарии (14)
  10. C# / Говнокод #13161

    +137

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    int i, j;
    for (i = 0; i < n; i++)
    {
      for (j = 0; j < m; j++)
      {
        A[i, j] = Ain[i, j];
        b[i, 0] = bin[i, 0];
      }
    }

    C ninja style

    fasol8, 12 Июня 2013

    Комментарии (14)
  11. C# / Говнокод #13135

    +124

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    private void HideActiveButtons()
    {
        try
        {
    
        }
        catch (Exception)
        {
            throw;
        }
    }

    Откопано в форме Windows Forms в страшном legacy-коде.

    someone, 09 Июня 2013

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