66 lines
1.3 KiB
C++
66 lines
1.3 KiB
C++
#include <iostream>
|
|
#include <vector>
|
|
#include <bits/stdc++.h>
|
|
|
|
using std::cout;
|
|
using std::endl;
|
|
using std::cin;
|
|
using std::vector;
|
|
using std::string;
|
|
|
|
int main() {
|
|
vector<int> x;
|
|
|
|
string line;
|
|
int number;
|
|
bool vectorEnd = false;
|
|
|
|
int min, max;
|
|
|
|
// Prendo in input min e max
|
|
cout << "Min = ";
|
|
cin >> min;
|
|
cout << "Max = ";
|
|
cin >> max;
|
|
|
|
// Prendo in input il vettore x
|
|
cout << "Inserisci gli elementi di X, un numero per riga." << endl
|
|
<< "Per terminare l'inserimento inserire una riga vuota o non valida." << endl;
|
|
|
|
getline(cin, line);
|
|
while (!vectorEnd) {
|
|
cout << "> ";
|
|
getline(cin, line);
|
|
try {
|
|
number = std::stoi(line);
|
|
if(number >= min && number <= max) {
|
|
x.push_back(number);
|
|
}
|
|
} catch (std::exception ex) {
|
|
vectorEnd = true;
|
|
}
|
|
}
|
|
|
|
if (max > min) { // Verifico input
|
|
std::sort(x.begin(), x.end());
|
|
|
|
int i = min;
|
|
|
|
while (!x.empty()) {
|
|
for (; i < x[0]; i++) {
|
|
cout << i << endl;
|
|
}
|
|
x.erase(x.begin());
|
|
i++;
|
|
}
|
|
for (; i <= max; i++) {
|
|
cout << i << endl;
|
|
}
|
|
} else {
|
|
cout << "Input non valido." << endl;
|
|
}
|
|
|
|
|
|
return 0;
|
|
}
|