1. 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)
  2. Java / Говнокод #13418

    +70

    1. 1
    final int mazeBlockSize = mazeBlock.getIconWidth();       // it is square, OKAY?!

    Как я пакмена писал

    vortexx1, 13 Июля 2013

    Комментарии (19)
  3. Си / Говнокод #13416

    +129

    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
    #include <stdio.h>
    #include <conio.h>
    #include <string.h>
    void swap (char *x, char *y)
    {
        char temp;
        temp = *x;
        *x = *y;
        *y = temp;
    }
     
    void permute(char *a, int i, int n)
    {
        int j;
        if (i == n)
        printf("%s\n", a);
        else
        {
            for (j = i; j <= n; j++)
            {
                swap((a+i), (a+j));
                permute(a, i+1, n);
                swap((a+i), (a+j));
            }
        }
    }
     
     
    int main()
    {
        char str[80] ;
        int len=0,i;
        puts("Enter a string:\n\n");
        gets(str);
        for (i=0; str[i] != '\0'; i++)
        {
            len++;
        }
        permute(str, 0, len);
        getchar();
        return 0;
    }

    Источник:
    http://www.c-program-example.com/2012/04/c-program-to-find-all-permutations-of.html

    про strlen видимо никто не слышал

    denis90, 13 Июля 2013

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

    +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
    getCastIds:
            function(checkCast){
                var i
                  , castIds = [this.cancelBlesId]
                  ;
                if(checkCast)
                {
                    for(i = 0; i < castIds.length; i++)
                    {
                      if(Empire.asset(castIds[i]))
                      {
                        castIds.splice(i,1);
                        i--;
                      }
                    }
                }
                return castIds.length ? castIds : [0];
            }

    Выстрелим себе в ногу.

    dioteos, 12 Июля 2013

    Комментарии (24)
  5. Куча / Говнокод #13413

    +132

    1. 1
    У МИНЯ ЕСТЬ АЙФОН 5 И БАЛЬШОЙ ДОМ В МАЙНКРАВТЕ А ЧИВО ДАБИЛСЯ ТЫ?

    Я БАГАТ И УСПЕШОН

    PragramistOtBoga, 12 Июля 2013

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

    +86

    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
    96. 96
    procedure TForm1.Colorize;
    procedure SetStr(var s: string; const Style: TFontStyles; const Color, BackColor: Byte);
    var
      Format: TCharFormat2;
    begin
     If s<>'' Then
      begin
        FillChar(Format, SizeOf(Format), 0);
        Format.cbSize := SizeOf(Format);
        Format.dwMask:= CFM_BACKCOLOR or CFM_COLOR;
        Format.crBackColor:= GetIRCColor(BackColor, True);
        Format.crTextColor:= GetIRCColor(Color);
        if RichEdit1.HandleAllocated then
        SendMessage(RichEdit1.Handle, EM_SETCHARFORMAT, SCF_SELECTION,
          LPARAM(@Format));
        RichEdit1.SelAttributes.Style:= Style;
        RichEdit1.SelText:= s;
        RichEdit1.SelAttributes.Assign(RichEdit1.DefAttributes);
        s:= ''
      end;
    end;
    var
      Color, BackColor: Byte;
      Style: TFontStyles;
      CurrStr: string;
      I: Integer;
    begin
      Style:= [];
      Color:= DefForeColor;
      BackColor:= DefBackColor;
      CurrStr:= '';
      I:= 0;
      While (I<Length(Str))do
       begin
        Inc(I);
        case Str[I] of
          #31:
              begin
               SetStr(CurrStr, Style, Color, BackColor);
               If fsUnderLine in Style Then
                Exclude(Style, fsUnderLine)
               else
                Include(Style, fsUnderLine);
             end;
          #2:
             begin
               SetStr(CurrStr, Style, Color, BackColor);
               If fsBold in Style Then
                Exclude(Style, fsBold)
               else
                Include(Style, fsBold);
             end;
           #15, #13:
               begin
                SetStr(CurrStr, Style, Color, BackColor);
                Color:= DefForeColor;
                BackColor:= DefBackColor;
               end;
           #3:
              begin
                SetStr(CurrStr, Style, Color, BackColor);
                Inc(I);
                Color:= DefForeColor;
                If (Str[I] in ['0', '1'..'9'])Then
                 begin
                  Color:= StrToInt(Str[I]);
                  Inc(I);
                  If (Str[I] in ['0', '1'..'9'])Then
                   begin
                     Color:= StrToInt(IntToStr(Color)+Str[I]);
                     Inc(I)
                   end;
                 end;
                 If Str[I] = ',' Then                         //BackColor
                   begin
                    BackColor:= DefBackColor;
                    Inc(I);
                    If (Str[I] in ['0', '1'..'9'])Then
                     begin
                      BackColor:= StrToInt(Str[I]);
                      Inc(I);
                      If (Str[I] in ['0', '1'..'9'])Then
                       begin
                        BackColor:= StrToInt(IntToStr(BackColor)+Str[I]);
                        Inc(I)
                       end;
                      end;
                    end;
                   Dec(I) 
              end;
           else
            CurrStr:= CurrStr+Str[I]
        end;
       end;
       SetStr(CurrStr, Style, Color, BackColor);
    end;

    Процедура раскрашивающая текст из Log-файла mIRC загруженого в TRichEdit на форме.

    function GetIRCColor(const Color: Byte; const Back: Boolean=False): TColor;
    begin
    case Color of
    0: Result:= clWhite;
    1: Result:= clBlack;
    2: Result:= clNavy;
    3: Result:= clGreen;
    4: Result:= clRed;
    5: Result:= clMaroon;
    6: Result:= clPurple;
    7: Result:= $000080FF;
    8: Result:= clYellow;
    9: Result:= clLime;
    10: Result:= clTeal;
    11: Result:= clAqua;
    12: Result:= clBlue;
    13: Result:= clFuchsia;
    14: Result:= clGray;
    15: Result:= clSilver;
    else
    begin
    If Back Then
    Result:= clWhite
    else
    Result:= clBlack
    end;
    end;
    end;

    ASNightingale, 12 Июля 2013

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

    +11

    1. 1
    2. 2
    const listee* const nullablya = static_cast<listee*>(lst1);
    if(nullablya == NULL)

    LispGovno, 12 Июля 2013

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

    +6

    1. 1
    2. 2
    3. 3
    4. 4
    list* down_if_valid_me(void)
    {
    	return this ? this->down() : NULL;
    }

    LispGovno, 12 Июля 2013

    Комментарии (57)
  9. PHP / Говнокод #13409

    +157

    1. 1
    2. 2
    3. 3
    if (is_array(reset((array)$patentInfo))) {
    // ...
    }

    quall, 12 Июля 2013

    Комментарии (9)
  10. Си / Говнокод #13408

    +123

    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
    #include <malloc.h>
    #include <stdio.h>
    #include <string.h>
    #include <stdint.h>
    
    typedef struct {
      char * begin;
      uint64_t size, data_size;
    } str_t;
    
    inline uint64_t max(uint64_t a, uint64_t b) {
      return (a > b) ? a : b;
    }
    
    inline str_t correct_data_size(str_t str, uint64_t new_size) {
      if(str.data_size < new_size) {
        str.data_size = (max(str.data_size, new_size) << 1);
        str.begin = realloc(str.begin, str.data_size);    
      }
      return str;
    }
    
    inline str_t concat(str_t dest, str_t src) {
      uint64_t new_size = (dest.size + src.size - 1);
      dest = correct_data_size(dest, new_size);
      memcpy((dest.begin + dest.size - 1), src.begin, src.size);
      dest.size = new_size;
      return dest;
    }
    
    inline str_t create_str(char * str, uint64_t size) {
      return (str_t){.begin = strcat(malloc(size), str), .size = size, .data_size = size};
    }
    
    inline void print_str_t(str_t str) {
      fprintf(stderr, "str = %ssize = %lu, data_size = %lu\n", str.begin, str.size, str.data_size);
    }
    
    uint64_t test(uint64_t star_n, uint64_t n, str_t str, str_t * gstr) {
      uint64_t end = (star_n + n);
      do {
        *gstr = concat(*gstr, str);
        
        char * pos = gstr->begin;
        while((pos = strstr(pos, "efgh")))
          memcpy(pos,"____",4);
        
      } while((++star_n) != end);
      return star_n;
    }
    
    int main(void) {
      char data[] = "abcdefghefghefgh";
      str_t str = create_str(data, sizeof(data)); 
      str_t gstr = create_str("", 1);
      time_t starttime = time(NULL);
      
      uint64_t block_c = 0;
      
      while((block_c = test(block_c, ((256/16) * 1024), str, &gstr)) != (((256/16) * 1024) * 20))
        printf("%ldsec\t\t%lukb\n",time(NULL)-starttime,gstr.size/1024);
      
    }

    Минимально оптимизированный вариант в царь-стиле теста из предыдущего ГК. Никто не увидел и начали на меня кукарекать. То ещё ГК, давайте объясняйте что здесь говно.

    superhackkiller1997, 11 Июля 2013

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