Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 2
- #include <iostream>
- #include <vector>
- #include <string>
- using namespace std;
- int main() {
- setlocale(LC_ALL, "Russian");
- cout << "Вводите последовательность чисел \n(чтобы закончить - введите что-угодно, кроме числа):\n";
- vector<double> seq;
- string word = "";
- double num = 0, max = -DBL_MAX, newel = -DBL_MAX;
- while (true)
- {
- cin >> word;
- try {
- seq.push_back(stod(word));
- if (num > max) {
- max = num;
- }
- }
- catch(exception& e){
- break;
- }
- }
- cout << "\nВведите новый элемент:\n";
- while (true) {
- cin >> word;
- try {
- newel = stod(word);
- break;
- }
- catch (exception& e) {
- cout << " Вводите число!\n";
- }
- }
- for (size_t i = 0; i < seq.size(); i++) {
- if (seq[i] == max) {
- seq.insert(seq.begin() + i + 1, newel);
- }
- }
- cout << "Результат: \n";
- for (auto it = seq.begin(); it < seq.end(); it++) {
- cout << *it << " ";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment