1. C++ / Говнокод #8253

    +1005

    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
    memsize =
      strlen("cpy_dta.sh ");
    
    if ( memsize >= 4096 ) {
      sprintf( errMsg, "[%s] - ExecScript string too long", func);
      return -7;
    }
    
    sprintf( args, "cpy_dta.sh " );
    
    if ( 0 != ( rc = ::system ( args ) ) )
    {
      // ...
    }

    просто фейспалм.

    Dummy00001, 20 Октября 2011

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

    +1007

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    template <typename T, typename U>
    auto operator()(T&& t, U&& u) const
    -> decltype(forward<T>(t) + forward<U>(u)) {
        return forward<T>(t) + forward<U>(u);
    }

    ohlol, 17 Октября 2011

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

    +1000

    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
    #include <iostream>
    #include <stdio.h>
    #include <fcntl.h>
    #include <string>
    #define print(data) cout<<data<<endl;
    #define ord(data) int(data[0])
    #define str(data) char(data)
    #define open fopen
    #define write(f, data) fputc(data, f)
    using namespace std;
    string input()
    {
            string s;
            cin>>s;
            return s;
    };
    FILE* f;
    int chr;
     
    int main() {
            print("Enter:");
            f = open("code.txt", "w");
            chr = ord(input());
            print(chr);
            write(f, str(chr));
            return 0;
    }

    Вот такую лабу сдал студент 1го курса в нашем вузе. Сказал преподавателю, что ему очень нравится питон и он старается ему подражать.
    http://ideone.com/ctkFP

    ohlol, 17 Октября 2011

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

    +1007

    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
    void Image::CombineNoise(byte combineType, byte noiseType, cCol3D& maxcolor, Image* mask)
    {
    	byte *maskBf=0;
    	if(mask)
    	{
    		uint mask_pixels=mask->Width*mask->Height;
    		maskBf=(byte*)malloc(mask_pixels);
    		if(mask->Format!=ImageFormat_Luminance)
    		for(uint i=0, ic=0; i<mask_pixels; i++, ic+=mask->Components)
    			maskBf[i]=min((byte)255)((byte)(mask->Data[ic]*0.3f+mask->Data[ic+1]*0.59f+mask->Data[ic+2]*0.11f));
    		else memcpy(maskBf, mask->Data, mask_pixels);
    		if(mask->Width!=Width || mask->Height!=Height)
    		{
    			byte* maskBf2=ScaleImage(Width, Height, maskBf, mask->Width, mask->Height, 1);
    			free(maskBf);
    			maskBf=maskBf2;
    		}
    	}
    
    	uint pixels=Width*Height;
    	uint size=pixels*Components;
    	if(Data && Width>0 && Height>0)
    	{
    		if(noiseType==0 && Format!=ImageFormat_Luminance)	//Цветной шум
    		{
    			switch(combineType)
    			{
    			case 0:	//Модуляция
    				if(mask)
    				for(uint i=0, ic=0; ic<size; i++, ic+=Components)
    				{
    					if(maskBf[i]<=127) continue;
    					Data[ic]=min<byte>(Data[ic]*(rand()%maxcolor.r)/255)(255);
    					if(Components<2) continue;
    					Data[ic+1]=min<byte>(Data[ic+1]*(rand()%maxcolor.g)/255)(255);
    					if(Components<3) continue;
    					Data[ic+2]=min<byte>(Data[ic+2]*(rand()%maxcolor.b)/255)(255);
    				}
    				else
    				for(uint ic=0; ic<size; ic+=Components)
    				{
    					Data[ic]=min<byte>(Data[ic]*(rand()%maxcolor.r)/255)(255);
    					if(Components<2) continue;
    					Data[ic+1]=min<byte>(Data[ic+1]*(rand()%maxcolor.g)/255)(255);
    					if(Components<3) continue;
    					Data[ic+2]=min<byte>(Data[ic+2]*(rand()%maxcolor.b)/255)(255);
    				}
    				break;
    
    			case 1:	//Сложение
    				if(mask)
    				for(uint i=0, ic=0; ic<size; i++, ic+=Components)
    				{
    					float factor=maskBf[i]/255.0f;
    					Data[ic]=(byte)min(Data[ic]+(rand()%maxcolor.r*factor))(255);
    					if(Components<2) continue;
    					Data[ic+1]=(byte)min(Data[ic+1]+(rand()%maxcolor.g*factor))(255);
    					if(Components<3) continue;
    					Data[ic+2]=(byte)min(Data[ic+2]+(rand()%maxcolor.b*factor))(255);
    				}
    				else
    				for(uint ic=0; ic<size; ic+=Components)
    				{
    					Data[ic]=min<byte>(Data[ic]+(maxcolor.r>0? rand()%maxcolor.r: 0))(255);
    					Data[ic+1]=min<byte>(Data[ic+1]+(maxcolor.g>0? rand()%maxcolor.g: 0))(255);
    					Data[ic+2]=min<byte>(Data[ic+2]+(maxcolor.b>0? rand()%maxcolor.b: 0))(255);
    				}
    				break;
    
    			case 2:	//Вычитание
    				if(mask)
    				for(uint i=0, ic=0; ic<size; i++, ic+=Components)
    				{
    					float factor=maskBf[i]/255.0f;
    					Data[ic]=(byte)max(Data[ic]-(rand()%maxcolor.r*factor))(0);
    					if(Components<2) continue;
    					Data[ic+1]=(byte)max(Data[i+1]-(rand()%maxcolor.g*factor))(0);
    					if(Components<3) continue;
    					Data[ic+2]=(byte)max(Data[i+2]-(rand()%maxcolor.b*factor))(0);
    				}
    				else
    				for(uint ic=0; ic<size; ic+=Components)
    				{
    					Data[ic]=max<byte>(Data[ic]-rand()%maxcolor.r)(0);
    					if(Components<2) continue;
    					Data[ic+1]=max<byte>(Data[ic+1]-rand()%maxcolor.g)(0);
    					if(Components<3) continue;
    					Data[ic+2]=max<byte>(Data[ic+2]-rand()%maxcolor.b)(0);
    				}
    				break;
    				
    			case 3:	//Средний цвет
    //На говнокод не лезет больше. Такая гигантская функция.

    Одна из функций для генерации изображений. Решил не рефакторить, потому что всё равно всё буду переделывать.

    gammaker, 17 Октября 2011

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

    +168

    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
    void __fastcall TForm1::ShowBits(unsigned char data)
    {
       if(data&0x1)ImBit0->Canvas->Brush->Color=0x0000FF00;
       else ImBit0->Canvas->Brush->Color=clRed;
       ImBit0->Canvas->FillRect(TRect(0,0,ImBit0->Width,ImBit0->Height));
       if(data&0x2)ImBit1->Canvas->Brush->Color=0x0000FF00;
       else ImBit1->Canvas->Brush->Color=clRed;
       ImBit1->Canvas->FillRect(TRect(0,0,ImBit1->Width,ImBit1->Height));
       if(data&0x4)ImBit2->Canvas->Brush->Color=0x0000FF00;
       else ImBit2->Canvas->Brush->Color=clRed;
    
       ImBit2->Canvas->FillRect(TRect(0,0,ImBit2->Width,ImBit2->Height));
       if(data&0x8)ImBit3->Canvas->Brush->Color=0x0000FF00;
       else ImBit3->Canvas->Brush->Color=clRed;
    
       ImBit3->Canvas->FillRect(TRect(0,0,ImBit3->Width,ImBit3->Height));
       if(data&0x10)ImBit4->Canvas->Brush->Color=0x0000FF00;
       else ImBit4->Canvas->Brush->Color=clRed;
    
       ImBit4->Canvas->FillRect(TRect(0,0,ImBit4->Width,ImBit4->Height));
    
       if(data&0x20)ImBit5->Canvas->Brush->Color=0x0000FF00;
       else ImBit5->Canvas->Brush->Color=clRed;
       ImBit5->Canvas->FillRect(TRect(0,0,ImBit5->Width,ImBit5->Height));
    
       if(data&0x40)ImBit6->Canvas->Brush->Color=0x0000FF00;
       else ImBit6->Canvas->Brush->Color=clRed;
       ImBit6->Canvas->FillRect(TRect(0,0,ImBit6->Width,ImBit6->Height));
    
       if(data&0x80)ImBit7->Canvas->Brush->Color=0x0000FF00;
       else ImBit7->Canvas->Brush->Color=clRed;
       ImBit7->Canvas->FillRect(TRect(0,0,ImBit7->Width,ImBit7->Height));
    }

    Отображение состояния битов байта

    absolut, 17 Октября 2011

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

    +147

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    if (!cpMenu->IsSelected())
    	{
    		std::vector<UINT> menus;
    		menus.push_back(_menuIndex.Value);	
    		if (!_SelectMenu(cpTarget, _instanceID.HasValue ? _instanceID.Value : -1, &menus[0], (UINT)menus.size(), SelectionType::Exclusive))
    			return CPNGObject();
    	}

    Не смог обойтись без вектора...

    alexoy, 16 Октября 2011

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

    +148

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    #include <iostream>
    #include <Windows.h>
    
    int main()
    {
        unsigned char data[]={0xb8, 0x9a, 0x02, 0x00, 0x00, 0xc3};
        auto function=(int(*)())VirtualAlloc(nullptr, sizeof(data), MEM_COMMIT, PAGE_EXECUTE_READWRITE);
        memcpy(function, data, sizeof(data));
        std::cout << function();
        VirtualFree(function, 0, MEM_RELEASE);
        return 0;
    }

    Угадайте, что выведет эта программа?

    gammaker, 16 Октября 2011

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

    +162

    1. 001
    2. 002
    3. 003
    4. 004
    5. 005
    6. 006
    7. 007
    8. 008
    9. 009
    10. 010
    11. 011
    12. 012
    13. 013
    14. 014
    15. 015
    16. 016
    17. 017
    18. 018
    19. 019
    20. 020
    21. 021
    22. 022
    23. 023
    24. 024
    25. 025
    26. 026
    27. 027
    28. 028
    29. 029
    30. 030
    31. 031
    32. 032
    33. 033
    34. 034
    35. 035
    36. 036
    37. 037
    38. 038
    39. 039
    40. 040
    41. 041
    42. 042
    43. 043
    44. 044
    45. 045
    46. 046
    47. 047
    48. 048
    49. 049
    50. 050
    51. 051
    52. 052
    53. 053
    54. 054
    55. 055
    56. 056
    57. 057
    58. 058
    59. 059
    60. 060
    61. 061
    62. 062
    63. 063
    64. 064
    65. 065
    66. 066
    67. 067
    68. 068
    69. 069
    70. 070
    71. 071
    72. 072
    73. 073
    74. 074
    75. 075
    76. 076
    77. 077
    78. 078
    79. 079
    80. 080
    81. 081
    82. 082
    83. 083
    84. 084
    85. 085
    86. 086
    87. 087
    88. 088
    89. 089
    90. 090
    91. 091
    92. 092
    93. 093
    94. 094
    95. 095
    96. 096
    97. 097
    98. 098
    99. 099
    100. 100
    void getway(stack <int> &s, const vector <int> &p, int v) {
        while(v != -1)
        {
            s.push(v);
            v = p[v];
        }
    } void compose(int ** M1, int ** M2, int n, int **res) {
        int curs;
        for(int i = 0; i < n; ++i)
        {
            for(int j = 0; j < n; ++j)
            {
                curs = 0;
                for(int k = 0; k < n; ++k)
                {
                    curs += M1[i][k] * M2[k][j];
                }
                res[i][j] = curs;
            }
    
        }
    } int mindist(int from, int to) {
        if(from == to)
            return 0;
        int **res, **tmp;
        createMat(res, n);
        createMat(tmp, n);
        duplit(res, Matrix, n);
        for(int i = 1; i < n; ++i)
        {
            //show(res, n);
            if(res[from][to])
            {
                deleteMat(res, n);
                deleteMat(tmp, n);
                return i;
            }
            compose(res, Matrix, n, tmp);
            duplit(res, tmp, n);
        }
    }
    int main()
    {
        fin.open("input.txt");
        stack <int> s1, s2;
        int d1, d2, min;
        fin >> n;
        createMat(Matrix, n);
        fillnill(Matrix, n);
        getGr(n, n);
        fin >> from >> to;
        --from;
        --to;
        min = mindist(from, to);
        //cerr << min << endl;
        d.resize(n);
        p.resize(n);
        used.assign(n, false);
        breadth();
        if(used[to])
        {
            d1 = d[to];
            getway(s1, p, to);
            swap(from, to);
            used.assign(n, false);
            d.assign(n, 0);
            p.assign(n, 0);
            bfs();
            d2 = d[to];
            if(d1 > min)
            {
                d1 = d2 / 0;
            }
            if(!d2 || d2 >= d1)
            {
                cout << d1 << endl;
                while(!s1.empty())
                {
                    cout << (int(s1.top()) + 1) << " ";
                    s1.pop();
                }
            }
            else
            {
                d1 = d2 / 0;
                getway(s2, p, to);
                cout << d2 << endl;
                while(!s2.empty())
                {
                    cout << (int(s2.top()) + 1) << " ";
                    s2.pop();
                }
            }
        }
    
        else
        {
            cout << -1 << endl;
        }
    }

    поиск кратчайшего пути;-)

    Novi4oK, 13 Октября 2011

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

    +166

    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
    void sort(student x[], perech *&py)
         { int l;
           perech t;
           //perech *y;
           py=new perech[n];
           l=1; k=0;
           for(i=0; i<n; i++)
    	  { fl=0;
    	    for(j=0; j<l; j++)
    	       { if((strcmp(x[i].fam,py[j].fam)==0)&&((strcmp(x[i].im,py[j].im)!=0)||(strcmp(x[i].gr,py[j].gr)!=0)))
    		   { fl=1;
    	    py[j].ng++; break;
    		   }
    		 if(fl==0) { strcmp(py[l-1].fam,x[i].fam);
    			     py[l].ng=1; l++;
    			   }
    	       }
    	  }
           for(i=0; i<(l-1); i++)
    	  for(j=i+1; j<l; j++)
    	     if(py[i].ng<py[j].ng)
    	       { t=py[i];
    		 py[i]=py[j];
    		 py[j]=py[i];
    	       }
           for(i=1; i<l; i++)
    	  if(py[0].ng=py[i].ng)
    	    k++;
           k++;
           py=new perech[k];
           if(py==NULL) {
    		      cout<<"Net pamyati"; getch();
    		      k=0; delete []py; return;
    		    }
           for(i=0; i<l; i++)
    	  py[i]=py[i];
           delete []py;
           cout<<"Perechen' sformirovan:\n";
           getch();
           for(i=0; i<l; i++)
    	  cout<<py[i].fam<<" "<<py[i].ng<<endl;
           getch();
         }
    void outputFileStudent(perech x[])
         { int l;
           ofstream fout;
           char file[L];
           cout<<"Vvedite imya faila:\n"; cin>>file;
           fout.open(file);
           if(fout.fail()) { cout<<"Error... Press any key for exit";
    			 getch(); return;
    		       }
           for(i=0; i<l; i++)
    	  fout<<x[i].fam<<" "<<x[i].ng<<endl;
           cout<<"File save\n";
           getch();
         }
    void outputFileStudentBin(perech y[])
         { ofstream fout;
           char file[L];
           cout<<"Vvedite imya save fila:\n"; cin>>file;
           fout.open(file, ios::binary);
           if(fout.fail()) { cout<<file<<"ne sozdan\n"; getch(); return; }
           fout.write((char *) y, k*sizeof(perech()));
           if(fout.fail()) { cout<<"Oshibka zapisi\n"; getch(); return; }
           cout<<"Perechen save\n";
           getch();
           fout.close();
         }
    void inputFileStudentBin(perech *&px)
         { ifstream fin;
           char file[20];
           int l;
           perech t;
           cout<<"Vvedite imya save faila:\n"; cin>>file;
           fin.open(file);
           if(fin.fail()) { cout<<"Error\n"; getch(); return();}
           for(i=0; i<l; i++)
    	   fin>>t.fam>>t.ng;
           fin.close();
    
           if(px!=NULL) delete []px;
           fin.open(file);
           if(fin.fail()) { cout<<"Povtornaya oshibka\n"; getch();
    			delete []px; k=0; return; }
           for(i=0; i<k; i++)
    	  fin>>px[i].fam>>px[i].ng;
           cout<<"file vveden\n"; getch();
           for(i=0; i<l; i++)
    	  cout<<px[i].fam<<" "<<px[i].ng<<endl;
           getch();
           fin.close();
         }

    Новый стажер решил задачу про студентов, вызывая их в компилированном виде из модуля 1С.
    Не знал в какой раздел запостить, поэтому пощу в 1С
    Вообще-то в 1С своя база.

    alexoy, 10 Октября 2011

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

    +160

    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
    class array
    {
        int data[256];
        int p;
    
    public:
        array ():
            p (0)
        {}
    
        array & operator , (int a)
        {
            data[p++] = a;
            return *this;
        }
    
        array & operator = (const array & arr)
        {
            p = 0;
            memcpy (data, arr.data, sizeof (data));
            return *this;
        }
    
        int & operator [] (size_t i)
        {
            return data[i];
        }
    };
    
    #define _I array(),
    #define I_
    #define o_O ,
    
    int _tmain(int argc, _TCHAR* argv[])
    {
        array arr;
        arr = _I 1,2,3,4,5,6 I_;    // init
        arr o_O 7,8,9,10;           // append new
        arr o_O 11 o_O 12;          // append new
    }

    http://www.gamedev.ru/flame/forum/?id=153265#m4

    RS-232, 09 Октября 2011

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