Created
February 1, 2018 04:58
-
-
Save async-python/b35b4f45dcda9b050db65df26b7596da to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <algorithm> | |
#include <vector> | |
using namespace std; | |
class error{}; | |
int year_max = 99; | |
int day_max = 31; | |
int month_max = 12; | |
int min_value = 1; | |
int year_type = 2; | |
int day_type = 1; | |
int month_type = 0; | |
void keep_window_open() { | |
int x; | |
cin >> x; | |
} | |
vector<int> date_input() { | |
vector<int> x; | |
int user_input1, user_input2, user_input3; | |
cin >> user_input1 >> user_input2 >> user_input3; | |
x.push_back(user_input1); | |
x.push_back(user_input2); | |
x.push_back(user_input3); | |
sort(x.begin(), x.end()); | |
if (x[year_type] > year_max || x[year_type] < min_value) throw error(); | |
if (x[day_type] > day_max || x[day_type] < min_value) throw error(); | |
if (x[month_type] > month_max || x[month_type] < min_value) throw error(); | |
return x; | |
} | |
void screen_print(vector<int> x) { | |
for (int i = 0; i < x.size(); ++i) { | |
cout << x[i] << " "; | |
} | |
cout << endl; | |
} | |
int main() { | |
try { | |
vector<int> DATE = date_input(); | |
if (DATE[year_type] > day_max) { | |
if (DATE[day_type] == DATE[month_type]) { | |
screen_print(DATE); | |
} else if (DATE[day_type] <= month_max) { | |
cout << "ambiguous" << endl; | |
} | |
} | |
else if (DATE[year_type] != DATE[day_type]) { | |
cout << "ambiguous" << endl; | |
} else screen_print(DATE); | |
keep_window_open(); | |
} | |
catch (error()) { | |
cerr << "oops" << endl; | |
keep_window_open(); | |
} | |
catch (...) { | |
cerr << "oops" << endl; | |
keep_window_open(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment