Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <Windows.h>
- #include <locale>
- using namespace std;
- void SetColor(int text, int background)
- {
- HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
- SetConsoleTextAttribute(hStdOut, (WORD)((background << 4) | text));
- }
- int main() {
- setlocale(LC_ALL, "RUS");
- const int SIZE = 22;
- 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;
- cout << "Масив";
- SetColor(2, 0);
- cout << "22";
- SetColor(3, 0);
- cout << "елементів:" << endl;
- SetColor(4, 0);
- for (int i = 0; i < SIZE; i++) {
- if (a[i] < min) {
- indmin1 = i;
- min = a[i];
- }
- }
- min = 999999;
- for (int i = 0; i < SIZE; i++) {
- if (i != indmin1 && a[i] < min) {
- indmin2 = i;
- min = a[i];
- }
- }
- for (int i = 0; i < SIZE; i++) {
- if (i == indmin1 || i == indmin2) {
- SetColor(2, 0);
- cout << a[i] << ' ';
- SetColor(4, 0);
- }
- else
- cout << a[i] << ' ';
- }
- SetColor(3, 0);
- if (indmin1 > indmin2) swap(indmin1, indmin2);
- between = indmin2 - indmin1 - 1;
- after = SIZE - indmin2 - 1;
- cout << "\n\nКількість елементів до першого мінімального: ";
- SetColor(2, 0);
- cout << indmin1;
- SetColor(3, 0);
- cout << "\nКількість елементів між двома мінімальними: ";
- SetColor(2, 0);
- cout << between;
- SetColor(3, 0);
- cout << "\nКількість елементів після другого мінімального: ";
- SetColor(2, 0);
- cout << after;
- SetColor(3, 0);
- if (indmin1 > between) {
- if (indmin1 > after) Max = indmin1;
- else Max = after;
- }
- else {
- if (between > after) Max = between;
- else Max = after;
- }
- SetColor(2, 0);
- cout << endl << indmin1;
- SetColor(3, 0);
- if (indmin1 > between) cout << '>';
- else if (indmin1 == between) cout << '=';
- else cout << '<';
- SetColor(2, 0);
- cout << between;
- SetColor(3, 0);
- if (between > after) cout << '>';
- else if (between == after) cout << '=';
- else cout << '<';
- SetColor(2, 0);
- cout << after;
- SetColor(3, 0);
- cout << '=';
- SetColor(2, 0);
- cout << Max << endl;
- SetColor(3, 0);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement