1. Список говнокодов пользователя wtfcode

    Всего: 2

  2. Си / Говнокод #11347

    +133

    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
    int * lPtr=item;
    int * lPtrEnd = item + count;
    
    for (lPtr = item ; lPtr < lPtrEnd && *lPtr<fid ; lPtr+=4);
    if( lPtr >= lPtrEnd ) lPtr=lPtrEnd-1; // last element
    if(*lPtr != fid)
    {
            if(--lPtr >=item)
            {   
                    if(*lPtr!= fid)
                    {   
                            if(--lPtr >=item)
                            {   
                                    if(*lPtr!= fid)
                                    {   
                                            if(--lPtr >=item)
                                            {   
                                                    if(*lPtr!= fid)
                                                    {   
                                                            break; // value not found
                                                    }   
                                            } else break;
                                    }   
                            }  else break;
                    }   
            } else break;
    }
    
    
    if( lPtr > item)
    {
            while ( *(lPtr-1) == fid && lPtr > item) lPtr--; // first ocurence of fid
    }

    Быстрый алгоритм поиска

    wtfcode, 03 Июля 2012

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

    +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
    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
    // Array below is for faster processing of variable length fields with ascii length.
    // Varbuut sho var arii initcializeet dinamiski. 
    char an[1000][3] = 
    {
    	{'0','0','0'},{'0','0','1'},{'0','0','2'},{'0','0','3'},{'0','0','4'},{'0','0','5'},{'0','0','6'},{'0','0','7'},{'0','0','8'},{'0','0','9'},
    	{'0','1','0'},{'0','1','1'},{'0','1','2'},{'0','1','3'},{'0','1','4'},{'0','1','5'},{'0','1','6'},{'0','1','7'},{'0','1','8'},{'0','1','9'},
    	{'0','2','0'},{'0','2','1'},{'0','2','2'},{'0','2','3'},{'0','2','4'},{'0','2','5'},{'0','2','6'},{'0','2','7'},{'0','2','8'},{'0','2','9'},
    	{'0','3','0'},{'0','3','1'},{'0','3','2'},{'0','3','3'},{'0','3','4'},{'0','3','5'},{'0','3','6'},{'0','3','7'},{'0','3','8'},{'0','3','9'},
    // 84 lines deleted
    	{'8','8','0'},{'8','8','1'},{'8','8','2'},{'8','8','3'},{'8','8','4'},{'8','8','5'},{'8','8','6'},{'8','8','7'},{'8','8','8'},{'8','8','9'},
    	{'9','0','0'},{'9','0','1'},{'9','0','2'},{'9','0','3'},{'9','0','4'},{'9','0','5'},{'9','0','6'},{'9','0','7'},{'9','0','8'},{'9','0','9'},
    // 6 lines deleted
    	{'9','7','0'},{'9','7','1'},{'9','7','2'},{'9','7','3'},{'9','7','4'},{'9','7','5'},{'9','7','6'},{'9','7','7'},{'9','7','8'},{'9','7','9'},
    	{'9','8','0'},{'9','8','1'},{'9','8','2'},{'9','8','3'},{'9','8','4'},{'9','8','5'},{'9','8','6'},{'9','8','7'},{'9','8','8'},{'9','8','9'}
    };
    
    			int ll = f->cfg.len_len;
    			long dl = f->data_len;
    			// Prepare length
    			if ( NULL == dst )
    			{
    				dst_len = f->data_len + ll + 1 ;
    				dst = (char*) malloc ( dst_len );
    			}
    			else
    			//if( dst_len < ll + dl )
    			if( dst_len < (unsigned) (ll + dl) )
    			{
    				// TO DOO - error should be processed
    				break;
    			}
    			long i2;
    			if ( ll < 2 )
    			{
    				dst[0]=an[dl][2];
    			}
    			else if ( ll < 3 )
    			{
    				dst[0]=an[dl][1];
    				dst[1]=an[dl][2];
    			}
    			else if ( ll < 4 )
    			{
    				dst[0]=an[dl][0];
    				dst[1]=an[dl][1];
    				dst[2]=an[dl][2];
    			}
    			else if ( ll < 5 )
    			{
    				i2 = dl / 1000;
    				dst[0]=an[i2][2];
    				i2 = dl % 1000;
    				dst[3]=an[i2][2];
    				dst[2]=an[i2][1];
    				dst[1]=an[i2][0];
    			}
    			else if ( ll < 6 )
    			{
    				i2 = dl / 1000;
    				dst[0]=an[i2][1];
    				dst[1]=an[i2][2];
    				i2 = dl % 1000;
    				dst[4]=an[i2][2];
    				dst[3]=an[i2][1];
    				dst[2]=an[i2][0];
    			}
    			else
    			{
    				// General case
    				for ( int k = ll  ; k > 0  ; k-- )
    				{
    					dst[k-1] ='0' + dl % 10;
    					dl/=10;
    				}
    			}
    
    			dst[dl]=0;

    This is a faster version of itoa() or sprintf(str,"%d",value)...
    Unfortunately it has a bug - lines of array with numbers 890-899 and 990-999 is missing.

    wtfcode, 21 Марта 2012

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