From 516452436b9ce8a7af42dc21fb162f5d5b128abb Mon Sep 17 00:00:00 2001 From: FraioVeio Date: Sat, 26 Mar 2022 15:58:55 +0100 Subject: [PATCH] Add beautiful code :) --- .idea/vcs.xml | 6 ++++++ main.cpp | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 .idea/vcs.xml diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/main.cpp b/main.cpp index bc8f460..88c8768 100644 --- a/main.cpp +++ b/main.cpp @@ -1,6 +1,63 @@ #include +#include +#include + +using std::cout; +using std::endl; +using std::cin; +using std::vector; +using std::string; int main() { - std::cout << "Hello, World!" << std::endl; + vector 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; }