MaksNew

Untitled

Oct 30th, 2020
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.91 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <math.h>
  4. #include <string>
  5. using namespace std;
  6.  
  7. int input(int& m) {
  8.     bool IsNotCorrect;
  9.     cout << "Введите m" << endl;
  10.     do {
  11.         IsNotCorrect = false;
  12.         try {
  13.             string value;
  14.             cin >> value;
  15.             m = stoi(value);
  16.         }
  17.         catch (...) {
  18.             cout << "Введите натуральное число" << endl;
  19.             IsNotCorrect = true;
  20.         }
  21.         if (m <= 0 && !IsNotCorrect) {
  22.             cout << "Введите натуральное положительное число" << endl;
  23.             IsNotCorrect = true;
  24.         }
  25.     } while (IsNotCorrect);
  26.     return m;
  27. }
  28.  
  29.  
  30. bool getBool(int m, int** sos, int *count) {
  31.     int x;
  32.     int y;
  33.     int z;
  34.     int x3;
  35.     int y3;
  36.     int z3;
  37.     int j;
  38.     int i;
  39.     int msqr;
  40.     int order;
  41.     bool boof;
  42.     i = 0;
  43.     order = (*count);
  44.     msqr = round(sqrt(m / 3));
  45.     boof = true;
  46.     for (int i = 0; i < order; i++)
  47.     {
  48.         sos[i] = new int[3];
  49.     }
  50.     for (x = 1; x <= msqr; x++) {
  51.         x3 = x * x * x;
  52.         if (x3 < m) {
  53.             for (y = 1; y <= msqr; y++) {
  54.                 y3 = y * y * y;
  55.                 if (x3 + y3 < m) {
  56.                     for (z = 1; z <= msqr; z++) {
  57.                         z3 = z * z * z;
  58.                         j = x3 + y3 + z3;
  59.                         if (j == m) {
  60.                             sos[i][0] = x;
  61.                             sos[i][1] = y;
  62.                             sos[i][2] = z;
  63.                             i++;
  64.                             (*count)++;
  65.                             boof = false;
  66.                         }
  67.                     }
  68.                 }
  69.             }
  70.         }
  71.     }
  72.     return boof;
  73. }
  74.  
  75.  
  76.  
  77. void output(bool boof, int** sos, int count) {
  78.     if (!boof) {
  79.         cout << "Числа, удовлетворяющие условию:" << endl;
  80.         for (int i = 0; i < count; i++) {
  81.             for (int j = 0; j < 3; j++)
  82.             {
  83.                 cout << sos[i][j] << "\t";
  84.             }
  85.             cout << endl;
  86.         }
  87.     }
  88.     else {
  89.         cout << "Не удалось подобрать числа X, Y, Z для данного числа M" << endl;
  90.     }
  91. }
  92.  
  93. int main()
  94. {
  95.     int m;
  96.     bool boof;
  97.     int count;
  98.     int** sos = new int* [3];
  99.     setlocale(LC_ALL, "Russian");
  100.     m = input(m);
  101.     boof = getBool(m, sos, &count);
  102.     output(boof, sos, count);
  103. }
  104.  
Advertisement
Add Comment
Please, Sign In to add comment