Advertisement
R0M41K

distance

May 12th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. #include <iostream>
  2. #include <Windows.h>
  3. #include <locale>
  4. using namespace std;
  5.  
  6. void SetColor(int text, int background)
  7. {
  8. HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
  9. SetConsoleTextAttribute(hStdOut, (WORD)((background << 4) | text));
  10. }
  11.  
  12. int main() {
  13. setlocale(LC_ALL, "RUS");
  14. const int SIZE = 22;
  15. int a[SIZE] = {2,1,-7,-8,1,0,-2,1,-2,1,2,-6,-7,-9,0,6,1,8,4,4,-1,1}, indmin1 = 22, indmin2 = 22, min = 999999, between, after, Max;
  16. cout << "Масив";
  17. SetColor(2, 0);
  18. cout << "22";
  19. SetColor(3, 0);
  20. cout << "елементів:" << endl;
  21. SetColor(4, 0);
  22. for (int i = 0; i < SIZE; i++) {
  23. if (a[i] < min) {
  24. indmin1 = i;
  25. min = a[i];
  26. }
  27. }
  28. min = 999999;
  29. for (int i = 0; i < SIZE; i++) {
  30. if (i != indmin1 && a[i] < min) {
  31. indmin2 = i;
  32. min = a[i];
  33. }
  34. }
  35.  
  36. for (int i = 0; i < SIZE; i++) {
  37. if (i == indmin1 || i == indmin2) {
  38. SetColor(2, 0);
  39. cout << a[i] << ' ';
  40. SetColor(4, 0);
  41. }
  42. else
  43. cout << a[i] << ' ';
  44. }
  45. SetColor(3, 0);
  46. if (indmin1 > indmin2) swap(indmin1, indmin2);
  47. between = indmin2 - indmin1 - 1;
  48. after = SIZE - indmin2 - 1;
  49. cout << "\n\nКількість елементів до першого мінімального: ";
  50. SetColor(2, 0);
  51. cout << indmin1;
  52. SetColor(3, 0);
  53. cout << "\nКількість елементів між двома мінімальними: ";
  54. SetColor(2, 0);
  55. cout << between;
  56. SetColor(3, 0);
  57. cout << "\nКількість елементів після другого мінімального: ";
  58. SetColor(2, 0);
  59. cout << after;
  60. SetColor(3, 0);
  61.  
  62. if (indmin1 > between) {
  63. if (indmin1 > after) Max = indmin1;
  64. else Max = after;
  65. }
  66. else {
  67. if (between > after) Max = between;
  68. else Max = after;
  69. }
  70. SetColor(2, 0);
  71. cout << endl << indmin1;
  72. SetColor(3, 0);
  73. if (indmin1 > between) cout << '>';
  74. else if (indmin1 == between) cout << '=';
  75. else cout << '<';
  76. SetColor(2, 0);
  77. cout << between;
  78. SetColor(3, 0);
  79. if (between > after) cout << '>';
  80. else if (between == after) cout << '=';
  81. else cout << '<';
  82. SetColor(2, 0);
  83. cout << after;
  84. SetColor(3, 0);
  85. cout << '=';
  86. SetColor(2, 0);
  87. cout << Max << endl;
  88. SetColor(3, 0);
  89. return 0;
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement