DasShelmer

12.2.19+

Apr 25th, 2020
358
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.22 KB | None | 0 0
  1. // 2
  2. #include <iostream>
  3. #include <vector>
  4. #include <string>
  5. using namespace std;
  6.  
  7. int main() {
  8.     setlocale(LC_ALL, "Russian");
  9.     cout << "Вводите последовательность чисел \n(чтобы закончить - введите что-угодно, кроме числа):\n";
  10.     vector<double> seq;
  11.     string word = "";
  12.     double num = 0, max = -DBL_MAX, newel = -DBL_MAX;
  13.  
  14.     while (true)
  15.     {
  16.         cin >> word;
  17.         try {
  18.             seq.push_back(stod(word));
  19.             if (num > max) {
  20.                 max = num;
  21.             }
  22.         }
  23.         catch(exception& e){
  24.             break;
  25.         }
  26.     }
  27.  
  28.     cout << "\nВведите новый элемент:\n";
  29.     while (true) {
  30.         cin >> word;
  31.         try {
  32.             newel = stod(word);
  33.             break;
  34.         }
  35.         catch (exception& e) {
  36.             cout << "  Вводите число!\n";
  37.         }
  38.     }
  39.  
  40.     for (size_t i = 0; i < seq.size(); i++) {
  41.         if (seq[i] == max) {
  42.             seq.insert(seq.begin() + i + 1, newel);
  43.         }
  44.     }
  45.  
  46.     cout << "Результат: \n";
  47.     for (auto it = seq.begin(); it < seq.end(); it++) {
  48.         cout << *it << " ";
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment