Skip to content

Instantly share code, notes, and snippets.

@async-python
Created January 31, 2018 21:50
Show Gist options
  • Save async-python/ec729811ad09b0c19d804d9d95112ee4 to your computer and use it in GitHub Desktop.
Save async-python/ec729811ad09b0c19d804d9d95112ee4 to your computer and use it in GitHub Desktop.
#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 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