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

    +3

    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
    rule_t block_r = ch_p('{') >> *(~ch_p('}') | (~ch_p('{') >> block_r));
    	rule_t bin_r = str_p("0b") >> bin_p[assign(m)];
    	rule_t hex_r = str_p("0x") >> hex_p[assign(m)];
    	rule_t dec_r = uint_p[assign(m)];
      rule_t id_r = alpha_p >> *(alnum_p | ch_p('_') | ch_p('.'));
      rule_t string_r = ch_p('"') >> (*(~ch_p('"')))[assign(s)] >> ch_p('"');
      rule_t channel_r = str_p("channel") >> *(space_p) >> id_r[assign(s)][assign_a(ch.name,s)][push_back_a(lstJSVars_,s)] >> *(space_p) >> ch_p('{') >>
        *(space_p 
    			| (str_p("mode") >> *(space_p) >> ch_p('=') >> *(space_p) >> 
            	(str_p("in")[assign_a(ch.mode,(int)channel::IN)] | str_p("out")[assign_a(ch.mode,(int)channel::OUT)]) >> *(space_p) >> ch_p(';'))
    			| (str_p("number") >> *(space_p) >> ch_p('=') >> *(space_p) >> int_p[assign(ch.number)] >> *(space_p) >> ch_p(';')) 
    			| (str_p("channel") >> *(space_p) >> ch_p('=') >> *(space_p) >> int_p[assign(ch.ch)] >> *(space_p) >> ch_p(';')) 
    			| (str_p("gain") >> *(space_p) >> ch_p('=') >> *(space_p) >> int_p[assign(ch.gain)] >> *(space_p) >> ch_p(';')) 
    			| (str_p("type") >> *(space_p) >> ch_p('=') >> *(space_p) >>
    					(str_p("analog")[assign_a(ch.type,(int)channel::ANALOG)] | str_p("discrete")[assign_a(ch.type,(int)channel::DISCRETE)]) >> *(space_p) >> ch_p(';'))
    			| (str_p("mask") >> *(space_p) >> ch_p('=') >> *(space_p) >> 
    					(bin_r[assign_a(ch.mask,m)] | hex_r[assign_a(ch.mask,m)] | dec_r[assign_a(ch.mask,m)]) >> *(space_p) >> ch_p(';'))
        ) >>
        ch_p('}') >> *(space_p) >> ch_p(';'); 
      rule_t device_r = str_p("device_info") >> *(space_p) >> id_r[assign(dev_info_.name)] >> *(space_p) >> ch_p('{') >>
        *(space_p | 
          (str_p("device") >> *(space_p) >> ch_p('=') >> *(space_p) >> string_r[assign_a(dev_info_.dev,s)] >> *(space_p) >> ch_p(';')) | 
          (str_p("blocking") >> *(space_p) >> ch_p('=') >> *(space_p) >> 
            (str_p("true")[assign_a(dev_info_.blocking,true)] | str_p("false")[assign_a(dev_info_.blocking,false)]) >> *(space_p) >> ch_p(';')) |
          (str_p("freq_ch") >> *(space_p) >> ch_p('=') >> *(space_p) >> int_p[assign(dev_info_.freq_ch)] >> *(space_p) >> ch_p(';')) | 
          (str_p("freq_sel_ch") >> *(space_p) >> ch_p('=') >> *(space_p) >> int_p[assign(dev_info_.freq_sel_ch)] >> *(space_p) >> ch_p(';')) |
          (str_p("speed") >> *(space_p) >> ch_p('=') >> *(space_p) >> int_p[assign(dev_info_.speed)] >> *(space_p) >> ch_p(';')) | 
          channel_r[assign_a(v,ch)][push_back_a(lstChannels_,v)]
        ) >>
        ch_p('}') >> *(space_p) >> ch_p(';');
      rule_t var_r = (str_p("var") >> *(space_p) >> id_r[assign(s)][push_back_a(lstJSVars_,s)] >>*(~ch_p(';')) >> ch_p(';'))[assign(s)][push_back_a(lstVars,s)];
      rule_t function_r = str_p("function") >> *(~ch_p('`'));
    	//rule_t function_r = str_p("function") >> *(~ch_p('{')) >> block_r;
      rule_t script_r = str_p("script") >> *(space_p) >> ch_p('{') >>
        *(space_p |
          var_r[assign(s)][push_back_a(lstJSVars_,s)] |
          (function_r[assign(s)][push_back_a(lstFunc,s)] >> *(space_p) >> ch_p('`'))
        ) >>
        ch_p('}') >> *(space_p) >> ch_p(';');

    Из системы эмуляции полёта на тренажере.

    codemeow, 21 Января 2022

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

    +2

    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
    int f6(int* a,int k, double& min, int& n, int& count) {
    	int i;
    	min = a[0];//8
    	n = 0;
    	count = 0;
    	for (i = 0; i < k; i++) {
    		if (a[i] == 0) {
    			count += 1;
    		}
    		if (abs(10-abs(a[i])) < abs(min)) {
    			min = a[i];
    			n = i;
    		}
    	}
    	return 0;
    }

    Помогите!!Пожалуйста!!Надо найти ближайший элемент к 10ти и его номер, почему не работает??

    vanya_goy, 18 Января 2022

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

    −3

    1. 1
    https://t.me/stdvector

    го в вектор

    CkpunmoBbIu_nemyx, 12 Января 2022

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

    +2

    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
    struct S { struct Inner { }; };
    template<int N> struct X;
    auto refl = ˆS;
    auto tmpl = ˆX;
    void f() {
    typename [:refl:] * x; // OK: declares x to be a pointer-to-S
    [:refl:] * x; // error: attempt to multiply int by x
    [:refl:]::Inner i; // OK: splice as part of a nested-name-specifier
    typename [:refl:]{}; // OK: default-constructs an S temporary
    using T = [:refl:]; // OK: operand must be a type
    struct C : [:refl:] {}; // OK: base classes are types
    template [:tmpl:]<0>; // OK: names the specialization
    [:tmpl:] < 0 > x; // error: attempt to compare X with 0
    }

    и да, это приняли.
    https://lists.isocpp.org/sg7/2021/04/0226.php
    http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p2320r0.pdf

    digitalEugene, 07 Января 2022

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

    0

    1. 1
    assert(not std::isnan(std::lerp(a, b, INFINITY))); // lerp here can be -inf

    а вы говорите этим никто не пользуется

    https://en.cppreference.com/w/cpp/numeric/lerp

    digitalEugene, 05 Января 2022

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

    +1

    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
    #include <iostream>
    #include <cstdio>
     
    namespace std {
        namespace ios_base2 {
    	    extern struct sync_with_stdio_t {
    	    	void h(bool sync = true) {
    		    	ios_base::sync_with_stdio(sync);
    		    }
    	    } sync_with_stdio;
        }
    }
     
    int main() {
    	std::ios_base2::sync_with_stdio.h(false);
    	std::cout << "1";
    	printf("2");
    	std::cout << "3";
    	puts("");
    	return 0;
    }

    132

    https://ideone.com/NkGYUL

    3_dar, 25 Ноября 2021

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

    +1

    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
    // @param n `0 <= n`
    // @param m `1 <= m`
    // @return `(x ** n) % m`
    constexpr long long pow_mod_constexpr(long long x, long long n, int m) {
        if (m == 1) return 0;
        unsigned int _m = (unsigned int)(m);
        unsigned long long r = 1;
        unsigned long long y = safe_mod(x, m);
        while (n) {
            if (n & 1) r = (r * y) % _m;
            y = (y * y) % _m;
            n >>= 1;
        }
        return r;
    }
     
    // Reference:
    // M. Forisek and J. Jancina,
    // Fast Primality Testing for Integers That Fit into a Machine Word
    // @param n `0 <= n`
    constexpr bool is_prime_constexpr(int n) {
        if (n <= 1) return false;
        if (n == 2 || n == 7 || n == 61) return true;
        if (n % 2 == 0) return false;
        long long d = n - 1;
        while (d % 2 == 0) d /= 2;
        constexpr long long bases[3] = {2, 7, 61};
        for (long long a : bases) {
            long long t = d;
            long long y = pow_mod_constexpr(a, t, n);
            while (t != n - 1 && y != 1 && y != n - 1) {
                y = y * y % n;
                t <<= 1;
            }
            if (y != n - 1 && t % 2 == 0) {
                return false;
            }
        }
        return true;
    }
    template <int n> constexpr bool is_prime = is_prime_constexpr(n);

    https://codeforces.com/contest/1508/submission/113222414

    > if (n == 2 || n == 7 || n == 61) return true;

    Помню я как делал: подобрал 3 базовых числа, прогнал на всех интах, там где алгоритм ошибался - проифал вручную )))

    3_dar, 14 Ноября 2021

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

    +1

    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
    // https://github.com/gcc-mirror/gcc/blob/b0c83d59f44bf677c8d74acae228acf32719acb3/libstdc%2B%2B-v3/include/bits/regex_compiler.tcc#L446
      template<typename _TraitsT>
      template<bool __icase, bool __collate>
        bool
        _Compiler<_TraitsT>::
        _M_expression_term(pair<bool, _CharT>& __last_char,
    		       _BracketMatcher<_TraitsT, __icase, __collate>& __matcher)
        {
          if (_M_match_token(_ScannerT::_S_token_bracket_end))
    	return false;
    
          const auto __push_char = [&](_CharT __ch)
          {
    	if (__last_char.first)
    	  __matcher._M_add_char(__last_char.second);
    	else
    	  __last_char.first = true;
    	__last_char.second = __ch;
          };
          const auto __flush = [&]
          {
    	if (__last_char.first)
    	  {
    	    __matcher._M_add_char(__last_char.second);
    	    __last_char.first = false;
    	  }
          };
    
          if (_M_match_token(_ScannerT::_S_token_collsymbol))
    	{
    	  auto __symbol = __matcher._M_add_collate_element(_M_value);
    	  if (__symbol.size() == 1)
    	    __push_char(__symbol[0]);
    	  else
    	    __flush();
    	}
          else if (_M_match_token(_ScannerT::_S_token_equiv_class_name))
    	{
    	  __flush();
    	  __matcher._M_add_equivalence_class(_M_value);
    	}
          else if (_M_match_token(_ScannerT::_S_token_char_class_name))
    	{
    	  __flush();
    	  __matcher._M_add_character_class(_M_value, false);
    	}
          else if (_M_try_char())
    	__push_char(_M_value[0]);
          // POSIX doesn't allow '-' as a start-range char (say [a-z--0]),
          // except when the '-' is the first or last character in the bracket
          // expression ([--0]). ECMAScript treats all '-' after a range as a
          // normal character. Also see above, where _M_expression_term gets called.
          //
          // As a result, POSIX rejects [-----], but ECMAScript doesn't.
          // Boost (1.57.0) always uses POSIX style even in its ECMAScript syntax.
          // Clang (3.5) always uses ECMAScript style even in its POSIX syntax.
          //
          // It turns out that no one reads BNFs ;)
          else if (_M_match_token(_ScannerT::_S_token_bracket_dash))
    	{
    	  if (!__last_char.first)
    	    {
    	      if (!(_M_flags & regex_constants::ECMAScript))
    		{
    		  if (_M_match_token(_ScannerT::_S_token_bracket_end))
    		    {
    		      __push_char('-');
    		      return false;
    		    }
    		  __throw_regex_error(
    		    regex_constants::error_range,
    		    "Unexpected dash in bracket expression. For POSIX syntax, "
    		    "a dash is not treated literally only when it is at "
    		    "beginning or end.");
    		}
    	      __push_char('-');
    	    }
    	  else
    	    {
    	      if (_M_try_char())
    		{
    		  __matcher._M_make_range(__last_char.second, _M_value[0]);
    		  __last_char.first = false;
    		}
    	      else if (_M_match_token(_ScannerT::_S_token_bracket_dash))
    		{
    		  __matcher._M_make_range(__last_char.second, '-');
    		  __last_char.first = false;
    		}
    	      else
    		{
    		  if (_M_scanner._M_get_token()
    		      != _ScannerT::_S_token_bracket_end)
    		    __throw_regex_error(
    		      regex_constants::error_range,
    		      "Character is expected after a dash.");
    		  __push_char('-');
    		}
    	    }
    	}

    Читаю тут реализацию стандартной говнокрестовой библиотеки из GCC
    Какой багор )))

    j123123, 10 Ноября 2021

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

    −2

    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
    #include <iostream>
    #include <cmath>
    #include <signal.h>
    
    #define lovu struct
    #define cpp ptrdiff_t
    struct forever{};
    
    lovu forever hactehbka(void) {return {};}
    int love(void) {return 0;}
    void bacbka(void) {}
    auto bormand = (cpp(hactehbka) + cpp(bacbka)) != cpp(love);
    int main(void)
    {
        if(bormand)
            kill(bormand, SIGINT);
    
        auto sad = cpp(bacbka) - cpp(love),
            chance = cpp(love) - cpp(hactehbka),
            never = cpp(bacbka) - cpp(hactehbka);
        auto usocute = [chance, never, sad](void) -> void
        {
            putchar(sad * (chance - never / chance / 2) - sad / chance);
            putchar(sad * (chance - never / chance / 2) + sad / chance);
        };
        auto mydear = [chance, sad, never](void) -> void
        {
            putchar(sad * chance / (never / chance) + never / chance / 2 + (never + cpp(love) / (never / chance) - cpp(hactehbka) / (never / chance)) + never - (never / chance * 1.5));
            putchar(9 * chance + never / chance);
            putchar(std::abs(cpp(signal) - cpp(hactehbka) + chance * 2 + never * 3 + sad - 9) / std::pow(never / chance, 3));
        };
    
        putchar(sad * (chance - never / chance / 2));
        usocute();
        putchar(never * (chance - never / chance) + sad - (sad / (cpp(love) - cpp(hactehbka))) * (never / chance * 1.5));
        mydear();
        putchar(chance * 10 + never / chance);
        usocute();
        putchar((chance + never / chance / 2) * 10 + (never / chance) * 2);
        auto ohyes = 69.8886;
        putchar(ohyes);
        putchar(chance * 10 + never / chance);
        putchar(chance + never / chance / 2);
        putchar(never * (chance - never / chance) + sad - (sad / (cpp(love) - cpp(hactehbka))) * (never / chance * 1.5));
        mydear();
        for(auto&& c : {1.5f, 3.f, 6.5f})
            putchar(ohyes + M_PI + never / chance * c);
        putchar(ohyes);
        putchar(chance + never / chance * 1.5);
        return 0;
    }

    BACbKA, 05 Ноября 2021

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

    −1

    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 <cstdio>
    
    int main(void)
    {
        static char data[] = "sosu hui\n";
        __asm
        {
            mov eax, 0
            ploop:
                mov bl, [data + eax]
                push eax
                push bx
                call putchar
                pop bx
                pop eax
                inc eax
                cmp bl, 0
                jnz ploop
    
        }
    
        return 0;
    }

    digitalEugene, 05 Ноября 2021

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