Add beautiful code :)

This commit is contained in:
2022-03-26 15:58:55 +01:00
parent ee0bbb94dc
commit 516452436b
2 changed files with 64 additions and 1 deletions

View File

@@ -1,6 +1,63 @@
#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() {
std::cout << "Hello, World!" << std::endl;
vector<int> x;
string line;
int number;
bool vectorEnd = false;
int min, 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;
while (!vectorEnd) {
cout << "> ";
getline(cin, line);
try {
number = std::stoi(line);
x.push_back(number);
} catch (std::exception ex) {
vectorEnd = true;
}
}
// Prendo in input min e max
cout << "Min = ";
cin >> min;
cout << "Max = ";
cin >> max;
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;
}