Advertisement
SteelK

Untitled

May 8th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.29 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <cstdlib>
  4. #include <ctime>
  5. #include <cstring>
  6. #include <cmath>
  7.  
  8. using namespace std;
  9.  
  10. int one_max(int *in_mas, size_t in_dlina) {
  11.     int a = 0, max = 0, b = 0;
  12.     max = in_mas[0];
  13.     for (int i = 1; i < (in_dlina); i++) {
  14.         a = in_mas[i];
  15.         if (a>max) {
  16.             max = a;
  17.             b = i;
  18.         }
  19.  
  20.     }
  21.     return b;
  22. }
  23.  
  24.  
  25. int one_maxrecursia(int *in_mas, size_t in_dlina, int max, int i, int b, int a) {
  26.     if (i<in_dlina)
  27.     {
  28.         a = in_mas[i];
  29.         if (a>max) {
  30.             max = a;
  31.             b = i;
  32.             cout << "!b = " << b << endl;
  33.         }
  34.         return one_maxrecursia(in_mas, in_dlina, max, ++i, b, a);
  35.     }
  36.     else return b;
  37. }
  38.  
  39. int min_rasnost_modul(int *in_mas, unsigned int in_dlina) {
  40.     int a = 0, min = 0;
  41.     min = abs(abs(in_mas[1]) - abs(in_mas[0]));
  42.     for (unsigned int i = 1; i < (in_dlina - 1); i++) {
  43.         a = abs(abs(in_mas[i + 1]) - abs(in_mas[i]));
  44.         if (a<min)
  45.             min = a;
  46.     }
  47.     return min;
  48. }
  49. int min_rasnost_modulrecursia(int *in_mas, unsigned int in_dlina) {
  50.     if (in_dlina <= 1) {
  51.         return abs(abs(in_mas[1]) - abs(in_mas[0]));
  52.     }
  53.     return (abs(abs(in_mas[1]) - abs(in_mas[0])), min_rasnost_modulrecursia(in_mas + 1, in_dlina - 1));
  54. }
  55.  
  56. int main() {
  57.     int max;
  58.     setlocale(0, "");
  59.     int mas1[] = { 1,2,3,4,5 };
  60.     int mas2[] = { -9,8,4 };
  61.     int mas3[] = { 2,2,8,8 };
  62.     if (
  63.         (one_max(mas1, 5) == 4)
  64.         &&
  65.         (one_max(mas2, 3) == 1)
  66.         &&
  67.         (one_max(mas3, 4) == 2)
  68.         &&
  69.         (min_rasnost_modul(mas1, 5) == 1)
  70.         &&
  71.         (min_rasnost_modul(mas2, 3) == 1)
  72.         &&
  73.         (min_rasnost_modul(mas3, 4) == 0)
  74.         &&
  75.         (one_maxrecursia(mas1, 5, max = mas1[0], 1, 0, 0) == 4)
  76.         &&
  77.         (one_maxrecursia(mas2, 3, max = mas2[0], 1, 0, 0) == 1)
  78.         &&
  79.         (one_maxrecursia(mas3, 4, max = mas3[0], 1, 0, 0) == 2)) {
  80.         cout << "Good" << endl;
  81.         return 0;
  82.     }
  83.     cout << "Bad" << endl;
  84.  
  85.     cout << endl;
  86.     cout << (one_max(mas1, 5)) << endl;
  87.     cout << (one_max(mas2, 3)) << endl;
  88.     cout << (one_max(mas3, 4)) << endl;
  89.     cout << endl;
  90.     cout << (min_rasnost_modul(mas1, 5)) << endl;
  91.     cout << (min_rasnost_modul(mas2, 3)) << endl;
  92.     cout << (min_rasnost_modul(mas3, 4)) << endl;
  93.     cout << endl;
  94.     cout << (one_maxrecursia(mas1, 5, max = mas1[0], 1, 0, 0)) << endl;
  95.     cout << (one_maxrecursia(mas2, 3, max = mas2[0], 1, 0, 0)) << endl;
  96.     cout << (one_maxrecursia(mas3, 4, max = mas3[0], 1, 0, 0)) << endl;
  97.  
  98.     return 1;
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement