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

    0

    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
    #include "pch.h"
    #include <iostream>
    #include <conio.h>
    #include <math.h>
    #include <stdlib.h>
    #include <iomanip>
    
    using namespace std;
    
    int n=0, m=0, a[10][10];
    
    void inputSize();
    void input();
    void out(int);
    void problem();
    bool just(int);
    void menu();
    
    int main()
    {
    	setlocale(0, "rus");
    	menu();
    	return 0;
    }
    
    void inputSize() {
    	system("cls");
    	cout << "количество строк = "; cin >> n;
    	cout << "количество столбцов = "; cin >> m;
    }
    
    void input() {
    	system("cls");
    	if (n == 0 || m == 0) {
    		cout << "размер массива задан по умолчанию: 3х3";
    		n = m = 3;
    	}
    	for (int i = 0; i < n; i++) {
    		for (int j = 0; j < m; j++) {
    			cout << "a[" << i + 1 << "][" << j + 1 << "] = "; cin >> a[i][j];
    		}
    	}
    }
    
    void out(int x = 0 ) {
    	system("cls");
    	for (int i = 0; i < n; i++) {
    		for (int j = 0; j < m; j++) {
    			cout << setw(7) << a[i][j];
    		}
    	cout << endl;
    	}
    	cout << endl;
    	system("pause");
    }
    
    void problem() {
    	system("cls");
    	int sum = 0, k = 0;
    	for (int i = 0; i < n; i++) {
    		for (int j = 0; j < m; j++) {
    			if (just(a[i][j])) {
    				cout << "a[" << i + 1 << "][" << j + 1 << "]   ";
    				sum += a[i][j];
    				k++;
    			}
    		}
    	}
    	if (sum == 0) cout << "нет простых чисел"; 
    	else if (sum % k == 0) cout << "ср. арифм. - целое"; else cout << "ср. арифм - не целое";
    	_getch();
    }
    
    bool just(int n) {
    	if (n == 1)return false;
    	int c = sqrt(n);
    	for (int i = 2; i <= c; i++) if (n%i == 0) return false;
    	return true;
    }
    
    void menu() {
    	system("cls");
    	int ch = 0;
    	while (ch != 5) {
    		cout << "     МЕНЮ\n\n";
    		cout << "1. ввод размера массива\n";
    		cout << "2. ввод массива\n";
    		cout << "3. вывод массива\n";
    		cout << "4. решение задачи\n";
    		cout << "5. выход\n\n";
    		cout << ">>"; cin >> ch;
    
    		if (ch == 1) inputSize();
    		if (ch == 2) input();
    		if (ch == 3) out();
    		if (ch == 4) problem();
    		if (ch == 5) break;
    		system("cls");
    	}
    }

    maxrbs, 17 Октября 2019

    Комментарии (37)
  2. Куча / Говнокод #25965

    −103

    1. 1
    2. 2
    2 ноября собираемся в Севастополе!
    Пусть нерусь всякая к своим литвинам едет!

    BATHNK, 17 Октября 2019

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

    0

    1. 1
    2. 2
    3. 3
    if (res / 2 < ans) {
        ans = res / 2;
    }

    yuras, 17 Октября 2019

    Комментарии (17)
  4. Куча / Говнокод #25959

    −103

    1. 1
    Be cool, be aerocock! Buy aerocock sas na kilowatt vsego za 3k russkih rublikov!

    BelCodeMonkey, 16 Октября 2019

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

    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
    #include <iostream> #include <cmath> #include <iomanip> #include <random> using namespace std; 
    int main()
    {
        setlocale(LC_ALL, "Rus");
        double n; cout << "Введите точность вычисления: "; cin >> n;
        while (n < 0.000001 || n > 1)
        {
            cout << "Веденное не соответствует условию" << "\nВведите точность вычислений: " << endl; cin >> n;
        }
        random_device generator;  uniform_real_distribution<double> distribution(-700, 700); //потому что функция "sinh" не считает > 700 double x = distribution(generator)  cout << "На множестве R выбран x, равный: " << x << "\n";
        double sum = 0.0 double a = x; double t = 1;
        while (abs(a) >= n)
        {
            sum += a; a *= (x * x / ((t + 1) * (t + 2))); t += 2;
        } 
        double func = sinh(x);  double diff = abs(sum - func); cout << setprecision(ceil(log10(1 / n))) << "Результат функции: " << func <<"\nРезультат просчета ряда: " << sum << endl; cout << "Погрешность составляет: " << diff << endl;   
        return 0;

    Brutallprincess, 16 Октября 2019

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

    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
    #include <iostream>
    #include <cmath>
    #include <iomanip>
    #include <random>
    using namespace std;
     
    int main()
    {
        setlocale(LC_ALL, "Rus");
        double n;
        cout << "Введите точность вычисления: ";
        cin >> n;
     
        while (n < 0.000001 || n > 1)
        {
            cout << "Веденное не соответствует условию" << "\nВведите точность вычислений: " << endl;
            cin >> n;
        }
     
        //Рандомные числа с промежутком
        random_device generator;
        uniform_real_distribution<double> distribution(-700, 700); //потому что функция "sinh" не считает > 700
        double x = distribution(generator);
        cout << "На множестве R выбран x, равный: " << x << "\n";
     
        //Подсчёт формулы
        double sum = 0.0;
        double a = x;
        double t = 1;
        while (abs(a) >= n)
        {
            sum += a;
            a *= (x * x / ((t + 1) * (t + 2)));
            t += 2;
        }
     
        //Функция, сравнение, погрешность
        double func = sinh(x);
        double diff = abs(sum - func);
        cout << setprecision(ceil(log10(1 / n))) << "Результат функции: " << func <<"\nРезультат просчета ряда: " << sum << endl;
        cout << "Погрешность составляет: " << diff << endl;   
        return 0;

    Brutallprincess, 16 Октября 2019

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

    +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
    #include "pch.h"
    #include <iostream>
    #include <conio.h>
    #include <stdlib.h>
    #include <ctime>
    
    using namespace std;
    
    int main()
    {
    	setlocale(0, "rus");
    	int n, a[1000], max, c;
    	cout << "число элементов: "; cin >> n;
    	srand(time(0));
    	
    	cout << "\nчисла массива:\n";
    	for (int i = 0; i < n; i++) {
    		a[i] = rand() % 2000 -1000;
    		cout << a[i] << " ";
    		if (i == 0) max = abs(a[i]); else if (abs(a[i]) > max) max = abs(a[i]);
    	}
    	cout << "\n\nабс. максимум = " << max << endl;
    
    	for (int i = 0; i < n; i++) {
    		for (int j = n-1; j > 0; j--) {
    			if (a[j - 1] < a[j]) {
    				c = a[j - 1];
    				a[j - 1] = a[j];
    				a[j] = c;
    			}
    		}
    	}
    
    	cout << "\nотсортированный массив:\n";
    	for (int i = 0; i < n; i++) {
    		cout << a[i]<<" ";
    	}
    
    	_getch();
    	return 0;
    }

    maxrbs, 15 Октября 2019

    Комментарии (1)
  8. Java / Говнокод #25947

    −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
    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
    98. 98
    99. 99
    import java.util.Random;
    public class Main {
        public static void main(String[] args) {
            Galaxy g = new Galaxy(3,77,34);
            g.start();
        }
    }
    class Galaxy extends Thread {
        private int min = 1;
        private int max = 100;
        private final int step = 5;
        private final int TIME = 1000;
        volatile private int a, b, c;
        Galaxy(int a, int b, int c) {
            this.a = a;
            this.b = b;
            this.c = c;
        }
        public void start() {
            Thread t = new Thread(this, "one");
            t.start();
            Thread t2 = new Thread(this, "two");
            t2.start();
            Thread t3 = new Thread(this, "three");
            t3.start();
        } @Override
        public void run() { while(true) { try {
                    Thread.sleep(new Random().nextInt(TIME));
                    if(currentThread().getName().equals("one")) {
                        if(new Random().nextInt(2) == 1 && a > 0)
                            a--;
                        else {
                            if (a < max)
                                a++;
                        }
                        int var = a;
                        if(b == var || (b-1) == var || (b+1) == var)
                            if((b+step) > max)
                                b-=step;
                            if((b-step) < min)
                                b+=step;
                        if(c == var || (c-1) == var || (c+1) == var)
                            if((c+step) > max)
                                c-=step;
                            if((c-step) < min)
                                c+=step;
                    }
                  if(currentThread().getName().equals("two")) {
                        if(new Random().nextInt(2) == 1 && b > 0)
                            b--;
                        else {
                            if(b < max)
                                b++;
                        }
                        int var = b;
                        if(a == var || (a-1) == var || (a+1) == var) {
                            if((a+step) > max)
                                a-=step;
                            if((a-step) <= min)
                                a+=step;
                        }
                        if(c == var || (c-1) == var || (c+1) == var) {
                            if((c+step) > max)
                                c-=step;
                            if((c-step) <= min)
                                c+=step;
                        }
                    }
                   if(currentThread().getName().equals("three")) {
                        if(new Random().nextInt(2) == 1 && c > 0)
                            c--;
                        else {
                            if(c < max)
                                c++;
                        }
                        int var = c;
                        if(a == var || (a-1) == var || (a+1) == var) {
                            if((a+step) > max)
                                a-=step;
                            if((a-step) <= min)
                                a+=step;
                        }
                        if(b == var || (b-1) == var || (b+1) == var) {
                            if((b+step) > max)
                                b-=step;
                            if((b-step) <= min)
                                b+=step;
                        }
                    }
                    for(int i = min; i <= max; i++) {
                        int p = 0;
                        if(i == a || i == b || i == c)
                            p = 1;
                        System.out.print(p);
                    }
                    System.out.println();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }}}}

    После запуска ждал 10 минут. Но они так и не сблизились. Программа словно остерегается сближения. Как живая.
    Рашан ИИ!

    codershitter, 14 Октября 2019

    Комментарии (9)
  9. PHP / Говнокод #25946

    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
    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
    <?php
    
    define('MAX_NUMBER', 70);
    
    function factorial($value) {
        return array_reduce(range(1, $value), function($carry,$item){return $carry*$item;}, 1);
    }
    
    function R($value) {
        return floor(2*sqrt(log(($value))));
    }
    
    function make_chain($start, $length) {
        $chain['start'] = $start;
        for($i = 0; $i < $length; ++$i) {
            $hash = factorial($start);
            echo ">>> $start! == $hash\n";            // диагностическое сообщение
            $start = R($hash);
            if($start == 0) break;
        }
        $chain['end'] = $hash;
        echo "Chain from ${chain['start']} to ${chain['end']} is ready.\n"; // диагностическое сообщение
        return $chain;
    }
    
    function make_chains($count, $length) {
        $chains = [];
        mt_srand();
        for($i = 0; $i < $count; ++$i) {
            $number = mt_rand(0, MAX_NUMBER - 1);                // начинаем цепочку с псевдослучайного слова
            $chain = make_chain($number, $length);
            $hash = $chain['end'];                               // используем конец найденной цепочки как индекс для быстрого поиска
            if(!isset($chains[$hash])) $chains[$hash] = [];      // если такого хэша не было в корзине, инициализируем её
            if(!in_array($chain['start'], $chains[$hash])) {     // проверяем на дубли
                $chains[$hash][] = $chain['start'];              // добавляем начало цепочки в корзину
            }
        }
        return $chains;
    }
    
    function find_hash_in_basket($needle, $haystack_start, $haystack_end) {
        echo "Роемся в цепочке от $haystack_start до $haystack_end.\n";       // диагностическое сообщение
        $current_number = $haystack_start;
        do {
            $current_hash = factorial($current_number);         // <-- сюда вставьте нужную хэш-функцию
            if($current_hash <= $needle && $needle <= $current_hash * ($current_number + 1)) {
                 return $current_number;                  // нашли
            }
            $current_number = R($current_hash);  // роем в глубину
        } while($current_hash !== $haystack_end);
        return false; // не нашли
    }
    
    function search_hash($hash, $chains, $length) {
        $current_hash = $hash;
        for($i = 0; $i < $length; ++$i) {
              if(isset($chains[$current_hash])) {                // нашли хэш в одной из корзин
                  echo "Лезем в корзину $current_hash.\n";       // диагностическое сообщение
                  foreach($chains[$current_hash] as $start) {    // роемся в корзине
                      $result = find_hash_in_basket($hash, $start, $current_hash); // пытаемся найти в каждой из цепочек корзины
                      if($result) {
                          return $result;                        // конец поиска
                      }
                  }
              }
              $next_number = R($current_hash);             // копаем в глубину
              $current_hash = factorial($next_number);
        }
        return false; // не нашли
    }
    
    ///////////////////// ПРИМЕР //////////////////////////////////
    
    
    $chains = make_chains(10, 5);
    echo "Радужные таблицы готовы.\n";
    var_dump($chains);
    
    $hash = 721;
    echo "Пытаемся обратить $hash.\n";
    $number = search_hash($hash, $chains, 5);
    echo $number . "! <= $hash <= " . ($number+1) . "!\n";

    Безумная идея: использовать радужные таблицы для обращения математических функций. Например, радужная таблица для факториала:
    http://ideone.com/Q22EXy

    ropuJIJIa, 13 Октября 2019

    Комментарии (11)
  10. PHP / Говнокод #25945

    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
    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
    <?php
    
    function word_by_index($index, $dicts) {
        $sizes = array_map(function($val){return count($val);}, $dicts); // получаем размеры каждого словаря
        $result = '';
        foreach($sizes as $key=>$size) {
            $result .= $dicts[$key][$index % $size]; // сцепляем слово из частей
            $index = floor($index / $size);
        }
        return $result;
    }
    
    function R($hash, $dicts, $total) {
        $index = gmp_intval(gmp_mod(gmp_init($hash, 16), $total));
        return word_by_index($index, $dicts); 
    }
    
    function make_chain($start, $length, $dicts, $total) {
        $chain['start'] = $start;
        for($i = 0; $i < $length; ++$i) {
            $hash = md5($start);                    // <-- сюда вставьте нужную хэш-функцию
            // echo ">>> $hash : $start\n";            // диагностическое сообщение
            $start = R($hash, $dicts, $total);
        }
        $chain['end'] = $hash;
        echo "Chain from ${chain['start']} to ${chain['end']} is ready.\n"; // диагностическое сообщение
        return $chain;
    }
    
    function make_chains($count, $length, $dicts) {
        $sizes = array_map(function($val){return count($val);}, $dicts); // получаем размеры каждого словаря
        $total = array_reduce($sizes, function($carry,$item){return $carry*$item;}, 1); // произведение размеров словарей
        $chains = [];
        mt_srand();
        for($i = 0; $i < $count; ++$i) {
            $word = word_by_index(mt_rand(0, $total - 1), $dicts);  // начинаем цепочку с псевдослучайного слова
            $chain = make_chain($word, $length, $dicts, $total);
            $hash = $chain['end'];                               // используем конец найденной цепочки как индекс для быстрого поиска
            if(!isset($chains[$hash])) $chains[$hash] = [];      // если такого хэша не было в корзине, инициализируем её
            if(!in_array($chain['start'], $chains[$hash])) {     // проверяем на дубли
                $chains[$hash][] = $chain['start'];              // добавляем начало цепочки в корзину
            }
        }
        return $chains;
    }
    
    function find_hash_in_basket($needle, $haystack_start, $haystack_end, $dicts, $total) {
        echo "Роемся в цепочке от $haystack_start до $haystack_end.\n";       // диагностическое сообщение
        $current_word = $haystack_start;
        do {
            $current_hash = md5($current_word);         // <-- сюда вставьте нужную хэш-функцию
            if($current_hash === $needle) {
                 return $current_word;                  // нашли слово, хэш от которого равен заданному
            }
            $current_word = R($current_hash, $dicts, $total);  // роем в глубину
        } while($current_hash !== $haystack_end);
        return false; // не нашли
    }
    
    function search_hash($hash, $dicts, $chains, $length) {
        $sizes = array_map(function($val){return count($val);}, $dicts); // получаем размеры каждого словаря
        $total = array_reduce($sizes, function($carry,$item){return $carry*$item;}, 1); // произведение размеров словарей
        $current_hash = $hash;
        for($i = 0; $i < $length; ++$i) {
              if(isset($chains[$current_hash])) {                // нашли хэш в одной из корзин
                  echo "Лезем в корзину $current_hash.\n";       // диагностическое сообщение
                  foreach($chains[$current_hash] as $start) {    // роемся в корзине
                      $result = find_hash_in_basket($hash, $start, $current_hash, $dicts, $total); // пытаемся найти в каждой из цепочек корзины
                      if($result) {
                          return $result;                        // конец поиска
                      }
                  }
              }
              $next_word = R($current_hash, $dicts, $total);             // копаем в глубину
              $current_hash = md5($next_word);
        }
        return false; // не нашли
    }
    
    ///////////////////// ПРИМЕР //////////////////////////////////
    
    $dicts= array(
          array('свино',  'овце', 'тигро', 'косатко', 'зубро', 'волко', 'кото'),
          array('собака', 'бык',  'лев',   'дельфин', 'бизон')
    );
    
    $chains = make_chains(15, 15, $dicts);
    echo "Радужные таблицы готовы.\n";
    var_dump($chains);
    
    $hash = '360629d3cf05cee0240a23e1251c58a0';
    echo "Пытаемся обратить $hash.\n";
    $word = search_hash($hash, $dicts, $chains, 15);
    echo "$hash is reversed to $word.\n";

    По просьбам трудящихся.

    Выхлоп на Ideone:
    http://ideone.com/otdCDg

    ropuJIJIa, 13 Октября 2019

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