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

    +2

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    HRESULT SomeClass::GetVersion(std::wstring& version)
    {
        CComBSTR versionBstr;
        m_Interface->get_Version(&versionBstr);
        version = std::move(std::wstring((_bstr_t)versionBstr, versionBstr.Length()));
        return S_OK;
    }

    Как показать в одном методе (не)знание move семантики, правил приведения типов и COM фреймворка

    salamon_style, 18 Января 2019

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

    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
    #include <iostream>
    
    int main()
    {
    setlocale(LC_ALL, "Russian");
    long long int num;
    long long int divider = 1;
    int max = 0;
    int min = 9;
    std::cout.unsetf(std::ostream::unitbuf);
    std::cout « "Введите число: ";
    std::cin » num;
    while(num>=divider)
    {
    if(num/divider%10>max) max = num/divider%10;
    if(num/divider%10<min) min = num/divider%10;
    divider = divider * 10;
    }
    std::cout « max « " - большая цифра" « '\n';
    std::cout « min « " - меньшая цифра";
    return 0;
    }

    BelCodeMonkey, 14 Января 2019

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

    0

    1. 1
    2. 2
    Почему весь С++ засран явными неймспейсами std:: ?
    Если из-за коллизий, то почему с этим нету проблем в C#, Java?

    Lorip1971, 10 Января 2019

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

    −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
    std::optional<int64_t> readNumber(const wchar_t *&str)
    {
        const wchar_t *origStr = str;
    
        if (*str == L'-' || *str == L'+') {
            str++;
            if (!std::iswdigit(*str)) {
                str--;
                return {};
            }
        } else {
            if (!std::iswdigit(*str)) {
                return {};
            }
        }
    
        while (std::iswdigit(*str)) {
            str++;
        }
    
        return wcstoll(origStr, NULL, 10);
    }

    А всё потому, что доки по «wcstoll» надо читать!

    gost, 07 Января 2019

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

    +4

    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
    #include <stdio.h>
    #include <string>
    
    const struct FooAgeProperty {} age;
    const struct FooNameProperty {} name;
    
    template <typename T>
    struct FooPropertyAssignment {
    	FooPropertyAssignment(T* prop): prop(prop) { }
    
    	T* prop;
    };
    
    struct years {
    	int i;
    
    	years& operator=(FooPropertyAssignment<int> fpa) {
    		*fpa.prop = i;
    		return *this;
    	}
    };
    
    struct nam {
    	std::string s;
    
    	nam& operator=(FooPropertyAssignment<std::string> fpa) {
    		*fpa.prop = s;
    		return *this;
    	}
    };
    
    years operator""years(unsigned long long value) {
    	return { (int)value };
    }
    
    nam operator""_(const char* value, size_t) {
    	return { value };
    }
    
    struct NegativeFoo {
    	NegativeFoo(int* age, std::string* name): age(age), name(name) {}
    
    	int* age;
    	std::string* name;
    };
    
    FooPropertyAssignment<int> operator<(FooAgeProperty fap, NegativeFoo nfoo) {
    	return FooPropertyAssignment<int>(nfoo.age);
    }
    
    FooPropertyAssignment<std::string> operator<(FooNameProperty fnp, NegativeFoo nfoo) {
    	return FooPropertyAssignment<std::string>(nfoo.name);
    }
    
    struct Foo;
    Foo* nasty_global_variable;
    
    struct Foo {
    	Foo() {
    		nasty_global_variable = this;
    	}
    
    	NegativeFoo operator-() {
    		return NegativeFoo(&age, &name);
    	}
    
    	int age;
    	std::string name;
    };
    
    struct to_string {
    	struct foo {
    		foo(int (*)(const char*, ...)) {
    			printf(".old years %d am I and %s is name My\n", nasty_global_variable->age, nasty_global_variable->name.c_str());
    		}
    	};
    };
    
    int main() {
    	Foo foo;
    	5years = age<-foo;
    	"Billy"_ = name<-foo;
    	(to_string::foo)printf;
    }

    https://www.reddit.com/r/ProgrammerHumor/comments/acv2og/just_wrote_my_first_program_in_c/

    Nyamka, 06 Января 2019

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

    −1

    1. 1
    .

    Справедливо ли утверждение о том, что большинство из присутствующих дрочатся с программированием и прочей ойти хуйней почти всё свободное и всё рабочее время?

    crestoblyad, 05 Января 2019

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

    +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
    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
    97. 97
    #include <bits/stdc++.h>
    using namespace std;
    vector <pair<int,int> > vpp;
    long long vres = 0;
    int get_dist(pair<int,int> l, pair<int,int> r)
    {
        int ans1 = abs(l.first - r.first);
        int ans2 = abs(l.second - r.second);
        return ans1 + ans2;
    
    }
        pair<vector <pair<int,int> > , long long>  rec(const string &s, int id,long long len,pair<int,int> pos,vector <vector <pair<int,int> > > &cl, vector <pair<int,int> > p)
    {
        if(id == (int)s.size())
            return {p,len};
        int st = s[id] - 'a';
        pair<vector <pair<int,int> > , long long> ans,tmp;
    
        for(int j = 0; j < (int)cl[st].size(); ++j)
        {
            p.push_back({cl[st][j]});
            tmp = rec(s,id + 1, len + get_dist(pos, cl[st][j]), cl[st][j], cl,p);
            if(tmp.second >= ans.second)
            {
                ans = tmp;
            }
            p.pop_back();
        }
        return ans;
    }
    #define mag pair< pair< vector< pair<int,int> > , long long>  , pair< pair< int,int >,pair< int,int > > >
    mag raz(int l, int r,const string &s,vector <vector <pair<int,int> > > &cl)
    {
    
        mag v1,v2;
        vector <pair<int,int> > p;
        if(r - l >= 1)
        {
            int tm = (l + r) >> 1;
            v1 = raz(l,tm,s,cl);
            bool f = 1;
            if(tm + 1 > r)
            {
                v2 = v1;
                f = 0;
            }
            else
                v2 = raz(tm + 1,r,s,cl);
          //  int st1 = ar[v1.second.first.first][v1.second.first.second];
           // int st2 = ar[v2.second.first.first][v2.second.first.second];
            long long len = 0;
    
    ///merge
            int n = (int)v1.first.first.size();
            len += v1.first.second;
            for(int i = 0; i < n; ++i)
            {
                p.push_back(v1.first.first[i]);
            }
            if(f)
            {
                len += v2.first.second;
                int n = (int)v2.first.first.size();
                for(int i = 0; i < n; ++i)
                {
                    p.push_back(v2.first.first[i]);
                }
            }
            len += get_dist(v1.second.second, v2.second.first);
            return {{p,len}, {v1.second.second, v2.second.first}};
        }
    
        int st = s[l] - 'a';
        int x1 = rand() % (int)cl[st].size();
        p.push_back(cl[st][x1]);
       // cout << cl[st].size() << " " << l << " " << r <<'\n';
        return {{p,0},{cl[st][x1],cl[st][x1]}};
    }
    //pair<int,vector <pair<int,int> > > solve(ifstream &cin, ofstream &cout)
     void solve(ifstream &cin, ofstream &cout)
    {
        vector <int> used(26);
        vector <vector <pair<int,int> > > cl(26);
        int n, m ,l;
        cin >> n >> m >> l;
        vector <vector <char > > ar(n,vector <char> (m));
        for(int i = 0; i < n; ++i)
        {
            for(int j = 0; j < m; ++j)
            {
                cin >> ar[i][j];
            }
        }
        string s;
        cin >> s;
        for(int i = 0; i < n; ++i)
        {

    omnocoder, 04 Января 2019

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

    +2

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    struct ApplyFunctor {
      template <typename Rules, typename ... Args>
      bool operator()(const Rules &rules, Args && ... args) const {
        for (const auto &rule : rules) {
          if (!rule.apply(std::forward<Args>(args)...))
            return false;
        }
    
        return true;
      }
    };

    Perfect forwarding, сцуко, такой perfect. Но все же не заменяет мозг.

    Elvenfighter, 04 Января 2019

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

    −1

    1. 1
    .

    Есть ли в нашем community те, кто пишут на "PHP" 15 и более лет и в хуй не дують?

    crestoblyad, 04 Января 2019

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

    −1

    1. 1
    .

    Предлагаю написать топ 10 местных программистов, руководствуясь общением с ними в комментариях или восхищением глубиной знаний.

    crestoblyad, 02 Января 2019

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