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

    +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
    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
    #include <bits/stdc++.h> 
    using namespace std; 
    int main(){
    int x1,y1,x2,y2; 
    string xy1,xy2;
    cin>>xy1>>xy2;
    if (xy1[0]=='A')x1=1;
    if (xy1[0]=='B')x1=2;
    if (xy1[0]=='C')x1=3;
    if (xy1[0]=='D')x1=4;
    if (xy1[0]=='E')x1=5;
    if (xy1[0]=='F')x1=6;
    if (xy1[0]=='G')x1=7;
    if (xy1[0]=='H')x1=8;
    
    if (xy1[1]=='1')y1=1;
    if (xy1[1]=='2')y1=2;
    if (xy1[1]=='3')y1=3;
    if (xy1[1]=='4')y1=4;
    if (xy1[1]=='5')y1=5;
    if (xy1[1]=='6')y1=6;
    if (xy1[1]=='7')y1=7;
    if (xy1[1]=='8')y1=8;
    
    if (xy2[0]=='A')x2=1;
    if (xy2[0]=='B')x2=2;
    if (xy2[0]=='C')x2=3;
    if (xy2[0]=='D')x2=4;
    if (xy2[0]=='E')x2=5;
    if (xy2[0]=='F')x2=6;
    if (xy2[0]=='G')x2=7;
    if (xy2[0]=='H')x2=8;
    
    if (xy2[1]=='1')y2=1;
    if (xy2[1]=='2')y2=2;
    if (xy2[1]=='3')y2=3;
    if (xy2[1]=='4')y2=4;
    if (xy2[1]=='5')y2=5;
    if (xy2[1]=='6')y2=6;
    if (xy2[1]=='7')y2=7;
    if (xy2[1]=='8')y2=8;
    if  ((abs(x1-x2)==1&&abs(y1-y2)==0)||
    (abs(x1-x2)==0&&abs(y1-y2)==1)||
    (abs(x1-x2)==1&&abs(y1-y2)==1)||
    (y1==y2||x1==x2||abs(x1-x2)==abs(y2-y1))||
    (y1==y2||x1==x2)||
    (abs(x1-x2)==abs(y2-y1))||
    (abs(x1-x2)==1&&abs(y1-y2)==2)|| 
    (abs(x1-x2)==2&&abs(y1-y2)==1)|| 
    (x1==x2&&((y1==2&&y2==y1+2)||(y1>=2&&y2==y1+1))))
    {
    //king
    if(abs(x1-x2)==1&&abs(y1-y2)==0)
    cout<<"King\n";
    else if(abs(x1-x2)==0&&abs(y1-y2)==1)
    cout<<"King\n";
    else if(abs(x1-x2)==1&&abs(y1-y2)==1)
    cout<<"King\n";
    //queen
    if(y1==y2||x1==x2||abs(x1-x2)==abs(y2-y1))
    cout<<"Queen\n";
    //rook
    if(y1==y2||x1==x2)
    cout<<"Rook\n";
    //bishop
    if (abs(x1-x2)==abs(y2-y1))
    cout<<"Bishop\n";
    //knight
     if(abs(x1-x2)==1&&abs(y1-y2)==2) 
    cout<<"Knight\n";
    else if(abs(x1-x2)==2&&abs(y1-y2)==1) 
    cout<<"Knight\n";
    //pawn
    if(x1==x2&&((y1==2&&y2==y1+2)||(y1>=2&&y2==y1+1)))
    cout<<"Pawn\n";
    }
    else cout<<"Nobody";
    }

    Нашел его в старом добром ACMP и он работает

    sulka, 13 Сентября 2018

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

    0

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    #include <iostream>
    #include <stdio.h>
    using namespace std;
    
    int main() {
        ios::sync_with_stdio.h(false);
        cin.tie(0);
        cout.tie(0);
    }

    Чо за хуйня?

    LinuxGovno, 07 Сентября 2018

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

    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
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    #include<iostream>
    #include<fstream>
    #include<vector>
    using namespace std;
    string rec(const string str, char c){return str;} //syntax error : missing ';' before identifier 'rec', ')' before 'const',  ')', ';' before '{', 
                                                                                    //'str' : undeclared identifier, 'rec': identifier not found
    
    void cer(){}                                                            //'cer' : local function definitions are illegal
    
    main(){                                                                  //'main': identifier not found
    
    	string s, d="Math.cos",a;                  //missing '}' before identifier 's',  ';' before identifier 's', 's', 'd', 'a' : undeclared identifier
    	
            ifstream fin;
    	vector<string> mas; // 'std::vector' : 'string' is not a valid template type argument for parameter '_Ty', 'mas' : unknown size
                                                  //'std::vector' : no appropriate default constructor available
    
    fin.open(mDocWrite); //'void std::basic_ifstream<char,std::char_traits<char>>::open(const char *,std::ios_base::open_mode)' : 
                                            //cannot convert argument 1 from 'nsAutoPtr<nsHtml5Tokenizer>' to 'const wchar_t *'
                         //No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
    
    //if (fin.is_open()) cout<<"1";else	cout<<"0";
    while(fin>>s)    //'s' : undeclared identifier, fatal error C1903: unable to recover from previous error(s); stopping compilation
    	{bool f=0;
    		for(int i=0; i<s.size(); ++i)
    			if (s[i]==d[0])
    				{
    					f=1;
    					for (int j=0; j<s.size()&&j<d.size(); ++j)
    						if (d[j]!=s[i+j]) f=0;
    					if (f)
    						{
    							a.clear();
    							for (int j=0; j<i; ++j)
    								a=a+s[j];
    							a=a+"0.5*";
    							for (int j=i; j<s.size(); ++j)
    								a=a+s[j];
    						}
    				}
    						if (f)	{mas.push_back("\n");mas.push_back(a);mas.push_back("\n");}
    			else mas.push_back(s);
    			s=rec(s,'0');
    	}
    	ofstream fout;
    fout.open(mDocWrite);
    for (int i=0; i<mas.size(); ++i) fout<<mas[i]<<"\t";
    }

    предполагалось, что код будет уменьшать cos угла в два раза, но при компиляции выдает ошибки, логику большинства которых не могу понять. Ошибки указал в коде. Подскажите, что не так.

    DrAli, 04 Сентября 2018

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

    −6

    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
    class Foo {
    // ...
    private:
        std::vector<int>     v1_;
        std::vector<int>     v2_;
        
        void bar( const std::vector<int>& v ); 
    
    public:
        void doAction( int choice ) {
            if ( choice == 1 ) 
                bar( v1_ );
            else
                bar( v2_ );
        }
    };

    Почему передавать поля класса в свои же методы по ссылке\указателю -- это говнокод?
    Как этого избегать, чтобы получилось универсальней?

    OlegUP, 01 Сентября 2018

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

    0

    1. 1
    2. 2
    #define ONE_GB 1024
    #define FIVE_GB 5115

    Написано в очень известной Калифорнийской конторе

    Starl1ght, 30 Августа 2018

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

    +3

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    #include <set>
    #include <algorithm>
    
    bool overlap(const std::set<int>& s1, const std::set<int>& s2)
    {
        for( const auto& i : s1) {
            if(std::binary_search(s2.begin(), s2.end(), i))
                return true;
        }
        return false;
    }

    я зделял

    https://stackoverflow.com/a/29421606/1683138
    -- https://en.cppreference.com/w/cpp/container/set
    iterator Constant BidirectionalIterator

    roman-kashitsyn, 28 Августа 2018

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

    +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
    class TaxStorage {
    public:
      using TaxCode = Code<3>; // Code<int N, typename Storage = uint32_t> тип для маленьких строк
      using TaxType = Code<3>;
      using TaxId = std::tuple<TaxCode, TaxType>;
      using TaxMap = std::map<TaxId, int>
    
      using CityId = int;
      using TaxPointMap = std::unordered_map<CityId, TaxMap>;
    
      TaxMap forCityOrOther(const TaxPointMap& map, const CityId cityId) const {
        const auto found = map.find(cityId);
        return found == map.cend() ? map.at(OTHER_CITY) : *found; // должно быть found->second
      }
    }

    Dev: Ok GCC, tell me what is wrong.
    GCC: /home/whatever/project/TaxStorage.h:102: error: incompatible operand types ('const std::unordered_map<int, std::map<std::tuple<Code<3, unsigned int>, Code<3, unsigned int> >, std::vector<unsigned long, std::allocator<unsigned long> >, std::less<std::tuple<Code<3, unsigned int>, Code<3, unsigned int> > >, std::allocator<std::pair<const std::tuple<Code<3, unsigned int>, Code<3, unsigned int> >, std::vector<unsigned long, std::allocator<unsigned long> > > > >, std::hash<int>, std::equal_to<int>, std::allocator<std::pair<const int, std::map<std::tuple<Code<3, unsigned int>, Code<3, unsigned int> >, std::vector<unsigned long, std::allocator<unsigned long> >, std::less<std::tuple<Code<3, unsigned int>, Code<3, unsigned int> > >, std::allocator<std::pair<const std::tuple<Code<3, unsigned int>, Code<3, unsigned int> >, std::vector<unsigned long, std::allocator<unsigned long> > > > > > > >::mapped_type' (aka 'const std::map<std::tuple<Code<3, unsigned int>, Code<3, unsigned int> >, std::vector<unsigned long, std::allocator<unsigned long> >, std::less<std::tuple<Code<3, unsigned int>, Code<3, unsigned int> > >, std::allocator<std::pair<const std::tuple<Code<3, unsigned int>, Code<3, unsigned int> >, std::vector<unsigned long, std::allocator<unsigned long> > > > >') and 'const std::pair<const int, std::map<std::tuple<Code<3, unsigned int>, Code<3, unsigned int> >, std::vector<unsigned long, std::allocator<unsigned long> >, std::less<std::tuple<Code<3, unsigned int>, Code<3, unsigned int> > >, std::allocator<std::pair<const std::tuple<Code<3, unsigned int>, Code<3, unsigned int> >, std::vector<unsigned long, std::allocator<unsigned long> > > > > >')

    ДОКОЛЕ?!!

    Elvenfighter, 24 Августа 2018

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

    −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
    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
    /*
    	Программа для генерации и вывода разряженной матрицы
    	Специально для сайта govnokod.ru
    */
    #include <iostream>
    #include <cstdlib>
    #include <ctime>
    
    // Объявление переменных
    const int first_index_size=20;
    const int second_index_size=50;
    char matrix_array[first_index_size][second_index_size];
    
    enum border_style{
    	line,single 
    };
    
    void borders(border_style matrix_border)
    {
    	switch(matrix_border)
    	{
    		case 0:
    			for(int i=0; i<(second_index_size+2); i++)
    				std::cout<<"#";
    			std::cout<<"\n";
    			break;
    		case 1:
    			std::cout<<"#";
    	}
    }
    
    void rand_func_init()
    {
    	// Инициализация функции rand()
    	srand(time(0));
    	rand();
    }
    
    void matrix_init_zero()
    {
    	// Инициализация матрицы нулём	
    	for(int i=0; i<first_index_size; i++)
    		for(int t=0; t<second_index_size; t++)
    			matrix_array[i][t]=0;
    }
    
    void matrix_init_rand()
    {
    	// Заполнение матрицы
    	for(int i=0; i<first_index_size; i++)
    	{
    		int init_num=rand()%11;
    		while(init_num)
    		{
    			init_num--;
    			matrix_array[i][rand()%50]=149;
    		}
    	}
    }
    
    void matrix_print()
    {
    	// Вывод матрицы	
    	borders(line);
    	for(int i=0; i<first_index_size; i++)
    	{
    		borders(single);
    		for(int t=0; t<second_index_size; t++)	
    			std::cout<<matrix_array[i][t];
    		borders(single);
    		std::cout<<"\n";
    	}
    	borders(line);
    }
    
    int main()
    {
    	rand_func_init();
    	matrix_init_zero();
    	matrix_init_rand();
    	matrix_print();
    	return 0;
    }

    Разряженная матрица 20x50.
    Количество ненулевых значений от 0 до 10.

    BelCodeMonkey, 18 Августа 2018

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

    +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
    #include <iostream>
    #include <type_traits>
    #include <utility>
    #include <array>
    
    template<size_t Size, typename T, typename FunctorType, size_t... idx>
    constexpr std::array<decltype(std::declval<FunctorType>().operator()(std::declval<T>())), Size>
                  map_impl(const std::array<T, Size> & arr, FunctorType && f, std::index_sequence<idx...>)
    {
        return std::array{ f(std::get<idx>(arr))... };
    }
    
    template<size_t Size, typename T, typename FunctorType>
    constexpr std::array<decltype(std::declval<FunctorType>().operator()(std::declval<T>())), Size>
                  map(const std::array<T, Size> & arr, FunctorType && f)
    {
        return map_impl(arr, f, std::make_index_sequence<Size>{});
    }
    
    struct MyFunctor {
        constexpr float operator()(int arg)
        {
            return static_cast<float>(arg * arg) / 2.0f;
        }
    };
    
    int main()
    {
        constexpr std::array arr{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
    
        auto arrMappedFunctor = map(arr, MyFunctor{});
        auto arrMappedLambda = map(arr, [](int x) constexpr { return static_cast<float>(x * x) / 2.0f; });
    
        for (auto && x : arrMappedFunctor) {
            std::cout << x << ' ';
        }
        std::cout << std::endl;
        for (auto && x : arrMappedLambda ) {
            std::cout << x << ' ';
        }
        std::cout << std::endl;
        return 0;
    }

    0.5 2 4.5 8 12.5 18 24.5 32 40.5 50
    0.5 2 4.5 8 12.5 18 24.5 32 40.5 50


    Метушня выходит на новый уровень: полноценный map в compile-time. Поддерживает как ручные функторы с перегруженным operator(), так и constexpr-лямбды. При помощи небольшой модификации возможно реализовать поддержку кортежей с произвольными типами.

    gost, 18 Августа 2018

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

    0

    1. 1
    inline constexpr size_t hardware_destructive_interference_size = implementation-defined;

    This number is the minimum recommended offset between two concurrently-accessed objects to avoid
    additional performance degradation due to contention introduced by the implementation.


    Бля, пиздец. Модулей нет, строк нет, а комитет мутит какую-то хуиту космической глупости.

    gost, 12 Августа 2018

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