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

    +144

    1. 1
    2. 2
    info->cipher_oid = oid_to_string(p->header2->header3->header4->header5->cipher_oid);
    info->hash_oid = oid_to_string(p->header2->header3->header4->header5->hash_oid);

    Вчера наговнокодил.

    bormand, 18 Марта 2015

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

    +54

    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
    std::list<CCPoint> GameMap::stringToCCPArray(std::string points_string, float _x, float _y)
    {
    	points_string.push_back(' ');
    	std::list<CCPoint> CCPList = list<CCPoint>();
    	float x = 0.0f;
    	float y = 0.0f;
    	unsigned int len = 0;
    	bool isCurrentX = true;
    	for(std::string::iterator it = points_string.begin(); it != points_string.end(); ++it){
    		int q = 0;
    		len > 0 ? 
    			--len: (isdigit(*it) ? 
    				(q = atoi(&(*it)), len = countNumbersInInt(q), 
    				isCurrentX ?
    					x = atoi(&(*it)): y = atoi(&(*it))) : 
    				*it == ',' ? 
    					(isCurrentX = false): (CCPList.push_back(ccp(x,(-1 * y))), x = 0.0f, y = 0.0f, isCurrentX = true)) ;
    	}
    
    	return CCPList;
    }

    t0rmund, 18 Марта 2015

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

    +56

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    int count = 0;
    while (condition) {
        if (count == 5) { // Kind of like sleeping for 0.2 milliseconds
            Sleep(1);
            count = 0;
        }
        // Do whatever.
        count++;
    }

    Последний ответ, показывает способ усыпить комп на 0.2 ms. И это после ответов со всякими сокетами, boost-таймерами и прочей мутью. Ответ такой типа, эй, чуваки вы ничо не понимаете, вот как надо, удобно же че бы нет))
    http://stackoverflow.com/questions/85122/how-to-make-thread-sleep-less-than-a-millisecond-on-windows/11456112#11456112

    vitaly, 17 Марта 2015

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

    +58

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    unsigned long long int getSumUtil(unsigned long long int *st, unsigned long long int ss, unsigned long long int se, unsigned long long int qs, unsigned long long int qe, unsigned long long int index)
    
    //cout<<"here";
    
    //prunsigned long long intf("here");
    
    //printf("%llu\n%llu\n%c",i,j,type);

    По следам prunsigned intf из http://govnokod.ru/17791.
    http://www.codechef.com/viewplaintext/3039072
    Ctrl+H - наш ответ typedef!

    1024--, 16 Марта 2015

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

    +57

    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
    #include <cstdio>
    #include <cstring>
    
    int main() {
        unsigned long long int a[100000];
        unsigned long long int N;
        unsigned long long int max,max1;
        unsigned long long int maxC,maxC1;
        unsigned long long int maxN[100000];
        unsigned long long int ans = 0;
        unsigned long long int ans1 = 0;
        max = max1 = maxC = maxC1 = 0;
        scanf("%llu",&N);
        for (unsigned long long int i = 0; i < N; ++i) {
            scanf("%llu",a + i);
            if (a[i] > a[max]) {
                max1 = max;
                maxC1 = maxC;
    //            memcpy(maxN,maxN1,maxC*sizeof(unsigned long long int));
                max = i;
                maxC = 1;
                maxN[0] = max;
            } else if (a[i] == a[max]) {
                maxN[maxC++] = i;
            } else if (a[i] > a[max1]) {
                max1 = i;
                maxC1 = 1;
            } else if (a[i] == a[max1]) {
                maxC1++;
            }
        }
        if (maxC == 1) {
            ans = a[max];
            if (a[max] == a[max1] + 1) {
                if (a[max] < (maxC1 + 1) * a[max1]) {
                    printf("%llu\n",a[max]);
                    return 0;
                }
            }
            if (max > 0) {
                if (a[max - 1] + 1 < ans - 1) {
                    if (a[max - 1] + 1 == a[max1]) {
                        if (a[max1] * (maxC1 + 1 + (a[max] - 1 == a[max1]?1:0)) < ans) {
                            ans1 = a[max1] * (maxC1 + 1 + (a[max] - 1 == a[max1]?1:0));
                            if (ans > ans1) ans = ans1;
    //                        prunsigned long long intf ("1 : %d\n",ans);
                        }
                    }
                    else { 
                        ans1 = a[max] - 1 + (a[max] - 1 == a[max1]?a[max1] * maxC1:0);
                        if (ans > ans1) ans = ans1;
    //                    prunsigned long long intf ("2 : %d\n",ans);
                    }
                }
            }
            if (max < N - 2) {
                if (a[max + 1] + 1 < ans - 1) {
                    if (a[max + 1] + 1 == a[max1]) {
                        if (a[max1] * (maxC1 + 1 + (a[max] - 1 == a[max1]?1:0)) < ans) {
                            ans1 = a[max1] * (maxC1 + 1 + (a[max] - 1 == a[max1]?1:0));
                            if (ans > ans1) ans = ans1;
    //                        prunsigned long long intf ("3 : %d\n",ans);
                        }
                    }
                    else { 
                        ans1 = a[max] - 1 + (a[max] - 1 == a[max1]?a[max1] * maxC1:0);
                        if (ans > ans1) ans = ans1;
    //                    prunsigned long long intf ("4 : %d\n",ans);
                    }
                }
            }
            printf("%llu\n",ans);
            return 0;
        } // one max line
        bool f = true;
        bool f1 = true;
        if (a[max] * maxC > a[max] + 1) {
    //        prunsigned long long intf("here %d\n",maxC);
            for (unsigned long long int i = 0; i < maxC; ++i) {
                if (f1 && ((maxN[i] && a[maxN[i] - 1]) || (maxN[i] < N - 1 && a[maxN[i] + 1]))) f1 = false; // get from near line
                if (f && ((maxN[i] && a[maxN[i] - 1] < a[max] - 1) || (maxN[i] < N - 1 && a[maxN[i] + 1] < a[max] - 1))) f = false;
            }
        }
        ans1 = ans = maxC * a[max];
        
        if (!f && a[max] > 1) ans = (maxC - 1) * a[max];
        if (!f1) ans1 = a[max] + 1;
        printf("%llu\n",ans>ans1?ans1:ans);
        return 0;
    }

    Серега говнокодит задачу с OpenCup'a от 15.03.2015 (задача L - Бассейн счастья)

    kosta3ov, 15 Марта 2015

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

    +54

    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
    #include <iostream>
    using namespace std;
    
    struct Foo
    {
    	int i[0];
    };
    
    int main() {
    	// your code goes here
    	Foo f1;
    	Foo f2[5];
    	cout << sizeof(f1) << endl;
    	cout << sizeof(f2) << endl;
    	return 0;
    }

    http://rextester.com/NAA5246
    http://rextester.com/GKLFG82436
    http://rextester.com/SSZ22454
    http://rextester.com/ZEY11320

    DlangGovno, 14 Марта 2015

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

    +56

    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
    template<typename T, typename E=emp> class _interlock;
    		template<typename T> class _interlock
    			<T,
    			typename std::enable_if<
    				std::is_same<
    					typename std::conditional<
    						std::is_same<udi,typename std::make_unsigned<T>::type>::value,
    						udi,
    						uqi
    					>::type,
    					typename std::make_unsigned<T>::type
    				>::value
    			>::type
    			>
    		{
    		public:
    
    			_interlock
    				<T,
    				typename std::enable_if<
    				std::is_same<
    				typename std::conditional<
    				std::is_same<udi,typename std::make_unsigned<T>::type>::value,
    				udi,
    				uqi
    				>::type,
    				typename std::make_unsigned<T>::type
    				>::value
    				>::type
    				>
    				(T x=0)
    			{
    				number=x;
    			}
    
    			//Возвращается прежнее значение
    			T operator + (T x)
    			{
    				return (T)InterlockedExchangeAdd((_unsign_t*)&number,(_sign_t)x);
    			}
    
    			//Возвращается прежнее значение
    			T operator - (T x)
    			{
    				return (T)InterlockedExchangeAdd((_unsign_t*)&number,-(_sign_t)x);
    			}
    
    			//Чтение
    			T operator () ()
    			{
    				return number;
    			}
    
    			//Замена на x
    			T operator () (T x)
    			{
    				return (T)InterlockedExchange((_unsign_t*)&number,(_unsign_t)x);
    			}
    
    			//Сравнение с y, замена на x, если равны
    			T operator () (T x, T y)
    			{
    				return (T)InterlockedCompareExchange((_unsign_t*)&number,(_unsign_t)x,(_unsign_t)y);
    			}
    			
    			T operator ++ ()
    			{
    				return (T)InterlockedExchangeAdd((_unsign_t*)&number,1)+1;
    			}
    
    			T operator -- ()
    			{
    				return (T)InterlockedExchangeAdd((_unsign_t*)&number,-1)-1;
    			}
    
    			T operator ++ (int)
    			{
    				return (T)InterlockedExchangeAdd((_unsign_t*)&number,1);
    			}
    
    			T operator -- (int)
    			{
    				return (T)InterlockedExchangeAdd((_unsign_t*)&number,-1);
    			}
    
    		private:
    			typedef typename std::make_unsigned<T>::type _unsign_t;
    			typedef typename std::make_signed<T>::type _sign_t;
    			volatile T number;
    		};

    Функция "ИЛИ" для типов через type_traits для шаблона. А также атомарный: сумматор, счётчик, компаратор с возможностью условной и безусловной замены значения в одном лице. Для типов: udi (unsigned int), sdi (signed int), uqi (unsigned long long), sqi (signed long long). Тип emp = void (от слова empty).

    Tirannozavr, 13 Марта 2015

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

    +68

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    int a, b ;
    //some code
    int numCount = 0;
    while ((a + numCount++) < b)    // посчитать кол-во чисел между a и b, включая a и b
       ;

    это великолепно!

    Croessmah, 11 Марта 2015

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

    +54

    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
    void Game::initialize()
    {
        if (SDL_Init(SDL_INIT_VIDEO))
            exit(1);
        
        window = new Window("Game", 640, 480);
        try
        {
            window->create();
        }
        catch (const Exception& exception)
        {
            std::cout << exception.getError() << '\n';
            delete window;
            exit(1);
        }
        
        canvas = new Canvas();
        try
        {
            canvas->initialize(window->getWindow());
        }
        catch (const Exception& exception)
        {
            std::cout << exception.getError() << '\n';
            delete canvas;
            exit(1);
        }
    }

    jangolare, 09 Марта 2015

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

    +59

    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
    LPVOID  lpInfo = NULL;;
    UINT    unInfoLen = 0;
    
    DWORD  dwLangCode = 0;
    if (!GetTranslationId(lpInfo, unInfoLen, GetUserDefaultLangID(), dwLangCode, FALSE))
    {
        if (!GetTranslationId(lpInfo, unInfoLen, GetUserDefaultLangID(), dwLangCode, TRUE))
        {
          if (!GetTranslationId(lpInfo, unInfoLen, MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), dwLangCode, TRUE))
          {
            if (!GetTranslationId(lpInfo, unInfoLen, MAKELANGID(LANG_ENGLISH, SUBLANG_NEUTRAL), dwLangCode, TRUE))
              // use the first one we can get
              dwLangCode = *((DWORD*)lpInfo);
          }
        }
    }

    докомментировались, ебанатики...

    blackhearted, 06 Марта 2015

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