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

    +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 <iostream>
    
    int main(void)
    {
    char sep = '\n'  /1\
    ; int i = 68    /1  \
    ; while (i  ---      1\
                           \
                           /1/1/1                               /1\
                                                                /1\
                                                                /1\
                                                                /1\
                                                                /1\
                                /           1\
                               /            1 \
                              /             1  \
                             /              1   \
                             /1            /1    \
                              /1          /1      \
                               /1        /1        /1/1> 0) std::cout \
                                  <<i<<                               sep;
        return 0;
    }

    https://stackoverflow.com/a/65856842

    digitalEugene, 05 Февраля 2022

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

    0

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    #define as ;while
    
    int main(int argc, char* argv[])
    {
        int n = atoi(argv[1]);
        do printf("n is %d\n", n) as ( n --> 0);
        return 0;
    }

    digitalEugene, 05 Февраля 2022

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

    +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
    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
    #include <iostream>
    using namespace std;
    void Brezenhem(char **z, int x0, int y0, int x1, int y1)
    {
      int A, B, sign;
      A = y1 - y0;
      B = x0 - x1;
      if (abs(A) > abs(B)) sign = 1;
      else sign = -1;
      int signa, signb;
      if (A < 0) signa = -1;
      else signa = 1;
      if (B < 0) signb = -1;
      else signb = 1;
      int f = 0;
      z[y0][x0] = '*';
      int x = x0, y = y0;
      if (sign == -1) 
      {
        do {
          f += A*signa;
          if (f > 0)
          {
            f -= B*signb;
            y += signa;
          }
          x -= signb;
          z[y][x] = '*';
        } while (x != x1 || y != y1);
      }
      else
      {
        do {
          f += B*signb;
          if (f > 0) {
            f -= A*signa;
            x -= signb;
          }
          y += signa;
          z[y][x] = '*';
        } while (x != x1 || y != y1);
      }
    }
    int main()
    {
      const int SIZE = 25; // размер поля
      int x1, x2, y1, y2;
      char **z;
      z = new char*[SIZE];
      for (int i = 0; i < SIZE; i++) 
      {
        z[i] = new char[SIZE];
        for (int j = 0; j < SIZE; j++)
          z[i][j] = '-';
      }
      cout << "x1 = ";     cin >> x1;
      cout << "y1 = ";     cin >> y1;
      cout << "x2 = ";     cin >> x2;
      cout << "y2 = ";    cin >> y2;
      Brezenhem(z, x1, y1, x2, y2);
      for (int i = 0; i < SIZE; i++) 
      {
        for (int j = 0; j < SIZE; j++)
          cout << z[i][j];
        cout << endl;
      }
      cin.get(); cin.get();
      return 0;
    }

    https://prog-cpp.ru/brezenham/

    спойлер: автор тян

    digitalEugene, 04 Февраля 2022

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

    0

    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
    class Solution
    {
    public:
    
        ListNode *reverseList1(ListNode* head){
            for (int i=1;i<6;i++) {
                head = new ListNode(1);
                head->val=i;
                head->next=last;
                printf("%d->",head->val);
            }
            printf("NULL");
    
        }
        ListNode *reverseList2(ListNode* head){
                head = nullptr;
                head = new ListNode(5);
                head->val = 5;
                printf("%d->",head->val);
                head->next = new ListNode(4);
                head->next->val=4;
                printf("%d->",head->next->val);
                head->next->next = new ListNode(3);
                head->next->next->val = 3;
                printf("%d->",head->next->next->val);
                head->next->next->next = new ListNode(2);
                head->next->next->next->val=2;
                printf("%d->",head->next->next->next->val);
                head->next->next->next->next = new ListNode(1);
                head->next->next->next->next->val=1;
                printf("%d->",head->next->next->next->next->val);
                head->next->next->next->next->next = nullptr;
                printf("NULL");
        }
    
    };

    От "разработчика" требовалось реализовать функции обращения связанного списка двумя способами.
    Занавес

    HMMMM, 03 Февраля 2022

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

    0

    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
    constexpr std::size_t find(string_view str, char c) noexcept {
    #if defined(__clang__) && __clang_major__ < 9 && defined(__GLIBCXX__) || defined(_MSC_VER) && _MSC_VER < 1920 && !defined(__clang__)
    // https://stackoverflow.com/questions/56484834/constexpr-stdstring-viewfind-last-of-doesnt-work-on-clang-8-with-libstdc
    // https://developercommunity.visualstudio.com/content/problem/360432/vs20178-regression-c-failed-in-test.html
      constexpr bool workaround = true;
    #else
      constexpr bool workaround = false;
    #endif
    
      if constexpr (workaround) {
        for (std::size_t i = 0; i < str.size(); ++i) {
          if (str[i] == c) {
            return i;
          }
        }
    
        return string_view::npos;
      } else {
        return str.find_first_of(c);
      }
    }

    какой constexpr)))

    digitalEugene, 02 Февраля 2022

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

    +2

    1. 1
    https://github.com/golded-plus/golded-plus/blob/master/golded3/gccfgg0.cpp#L162

    CHayT, 25 Января 2022

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

    0

    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
    class Foo {
        std::atomic<bool> a{false};
        std::atomic<bool> b{false};
    public:
        Foo()
        {
            
        }
    
        void first(function<void()> printFirst) {
            printFirst();
            a.store(true, std::memory_order_release);
        }
    
        void second(function<void()> printSecond) {
            while (!a.load(std::memory_order_acquire))
                ;
    
            printSecond();
            b.store(true, std::memory_order_release);
        }
    
        void third(function<void()> printThird) {
            while (!b.load(std::memory_order_acquire))
                ;
    
            printThird();
        }
    };

    https://leetcode.com/problems/print-in-order/

    36 / 36 test cases passed.
    Runtime: 1697 ms
    Memory Usage: 7 MB

    Хочу, чтобы начался срач по поводу того, как достичь рантайма в 200мс

    Nyanwitt, 24 Января 2022

    Комментарии (5)
  8. 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)
  9. 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)
  10. C++ / Говнокод #27946

    −3

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

    го в вектор

    CkpunmoBbIu_nemyx, 12 Января 2022

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