-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ad Hoc Problems - Part 2. Time (In progress)
- Loading branch information
Guilherme
committed
Sep 5, 2018
1 parent
adbc02a
commit a145ea8
Showing
15 changed files
with
67,473 additions
and
24 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,7 @@ | |
"tuple": "cpp", | ||
"typeinfo": "cpp", | ||
"utility": "cpp", | ||
"cstring": "cpp" | ||
"cstring": "cpp", | ||
"map": "cpp" | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/** | ||
* Guilherme de Novais Bordignon - UVA Judge Online Solution ${filename} | ||
* | ||
* This is a template file for C++ Solutions of UVA Judge Online problems | ||
**/ | ||
|
||
#include <cstdio> | ||
#include <cstdlib> | ||
#include <iostream> | ||
// #include <ctime> | ||
|
||
using namespace std; | ||
|
||
|
||
// bool isLeapYear(int year) | ||
// { | ||
// tm february29 = {0, 0, 0, 29, 1, year - 1900}; | ||
|
||
// return static_cast<time_t>(-1) != mktime(&february29) && | ||
// february29.tm_mday == 29 && | ||
// february29.tm_mon == 1 && | ||
// february29.tm_year == year - 1900; | ||
// } | ||
|
||
// bool isHuluculuYear(int year) | ||
// { | ||
// return year % 15; | ||
// } | ||
|
||
// bool isBulukuluYear(int year) | ||
// { | ||
// return year % 55; | ||
// } | ||
|
||
bool isLeapYear(string year) | ||
{ | ||
int size = year.size(); | ||
int fYear = stoi(year.substr(max(size - 4, 0))); | ||
return !(fYear & 3) && | ||
((fYear % 100) || !(fYear & 15)); | ||
} | ||
|
||
bool isHuluculuYear(string year) | ||
{ | ||
bool leapYear = false; | ||
int size = year.size(); | ||
int sum = 0; | ||
|
||
if (year.back() == '0' || year.back() == '5') | ||
{ | ||
for(int ii = 0; ii < size; ii++) { | ||
sum += year[ii] - '0'; | ||
} | ||
leapYear = (sum % 3) == 0; | ||
} | ||
return leapYear; | ||
} | ||
|
||
bool isBulukuluYear(string year) | ||
{ | ||
bool leapYear = false; | ||
int size = year.size(); | ||
int sum = 0; | ||
|
||
if (year.back() == '0' || year.back() == '5') | ||
{ | ||
for(int ii = 0; ii < size; ii++) { | ||
sum += (year[ii] - '0') * ( ii & 1 ? 1 : -1); | ||
} | ||
leapYear = (sum % 11) == 0; | ||
} | ||
return leapYear; | ||
} | ||
|
||
int main() | ||
{ | ||
int k = 0; | ||
string output = ""; | ||
string line; | ||
bool leapYear; | ||
|
||
output.reserve(500000); | ||
|
||
while(getline(cin, line)) | ||
{ | ||
int matches = 0; | ||
leapYear = isLeapYear(line); | ||
|
||
if (k++) output += "\n"; | ||
|
||
if (leapYear) | ||
{ | ||
output += "This is leap year.\n"; | ||
matches++; | ||
} | ||
if (isHuluculuYear(line)) | ||
{ | ||
output += "This is huluculu festival year.\n"; | ||
matches++; | ||
} | ||
if (leapYear && isBulukuluYear(line)) | ||
output += "This is bulukulu festival year.\n"; | ||
|
||
if (!matches) | ||
output += "This is an ordinary year.\n"; | ||
} | ||
|
||
printf("%s", output.c_str()); | ||
|
||
return(0); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/** | ||
* Guilherme de Novais Bordignon - UVA Judge Online Solution ${filename} | ||
* | ||
* This is a template file for C++ Solutions of UVA Judge Online problems | ||
**/ | ||
|
||
#include <cstdio> | ||
#include <iostream> | ||
#include <string> | ||
|
||
using namespace std; | ||
|
||
// int gcd(int a, int b) | ||
// { | ||
// return b == 0 ? a : gcd(b, (a % b)); | ||
// } | ||
|
||
int main() | ||
{ | ||
uint k, m, seconds, hour, minute, diff; | ||
const uint ONE_DAY = 24 * 3600; | ||
const uint HALF_DAY = 12 * 3600; | ||
char s[30]; | ||
string output = ""; | ||
string line; | ||
|
||
output.reserve(500000); | ||
|
||
while(true) | ||
{ | ||
cin >> k >> m; | ||
cin.ignore(); | ||
|
||
if (cin.eof()) break; | ||
|
||
diff = (k > m) ? k - m : m - k; | ||
|
||
// The 30 seconds makes it round automatically | ||
seconds = (HALF_DAY * (ONE_DAY - k) / diff) % HALF_DAY + 30; | ||
|
||
hour = (seconds / 3600) % 12; | ||
hour = (!hour ? 12 : hour); | ||
minute = (seconds / 60) % 60; | ||
|
||
sprintf(s, "%d %d %02d:%02d\n", k, m, hour, minute); | ||
output += s; | ||
} | ||
|
||
printf("%s", output.c_str()); | ||
|
||
return(0); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
/** | ||
* Guilherme de Novais Bordignon - UVA Judge Online Solution ${filename} | ||
* | ||
* This is a template file for C++ Solutions of UVA Judge Online problems | ||
**/ | ||
|
||
#include <cstdio> | ||
#include <cstdlib> | ||
#include <iostream> | ||
#include <map> | ||
#include <string> | ||
#include <ctime> | ||
|
||
using namespace std; | ||
|
||
void populateTZ(map<string, double> &tz) | ||
{ | ||
tz["UTC"] = 0; | ||
tz["GMT"] = 0; | ||
tz["BST"] = 1; | ||
tz["IST"] = 1; | ||
tz["WET"] = 0; | ||
tz["WEST"] = 1; | ||
tz["CET"] = 1; | ||
tz["CEST"] = 2; | ||
tz["EET"] = 2; | ||
tz["EEST"] = 3; | ||
tz["MSK"] = 3; | ||
tz["MSD"] = 4; | ||
tz["AST"] = -4; | ||
tz["ADT"] = -3; | ||
tz["NST"] = -3.5; | ||
tz["NDT"] = -2.5; | ||
tz["EST"] = -5; | ||
tz["EDT"] = -4; | ||
tz["CST"] = -6; | ||
tz["CDT"] = -5; | ||
tz["MST"] = -7; | ||
tz["MDT"] = -6; | ||
tz["PST"] = -8; | ||
tz["PDT"] = -7; | ||
tz["HST"] = -10; | ||
tz["AKST"] = -9; | ||
tz["AKDT"] = -8; | ||
tz["AEST"] = 10; | ||
tz["AEDT"] = 11; | ||
tz["ACST"] = 9.5; | ||
tz["ACDT"] = 10.5; | ||
tz["AWST"] = 8; | ||
} | ||
|
||
int main() | ||
{ | ||
int k = 0; | ||
int N; | ||
struct tm *date; | ||
time_t seconds, offset; | ||
string output = ""; | ||
string hour, period, tz1, tz2; | ||
int h, m; | ||
map<string, double> tz; | ||
|
||
populateTZ(tz); | ||
|
||
output.reserve(500000); | ||
cin >> N; | ||
cin.ignore(); | ||
|
||
seconds = time(0); | ||
seconds -= seconds % (24 * 3600); | ||
// date = localtime(&seconds); | ||
|
||
while(k++ < N) | ||
{ | ||
cin >> hour; | ||
|
||
if (hour == "noon") | ||
{ | ||
h = 12; | ||
m = 0; | ||
} else if (hour == "midnight") | ||
{ | ||
h = m = 0; | ||
} else | ||
{ | ||
cin >> period; | ||
|
||
h = stoi(hour.substr(0, hour.find(":"))) % 12; | ||
m = stoi(hour.substr(hour.find(":") + 1)); | ||
if (period == "p.m.") | ||
{ | ||
h += 12; | ||
} | ||
} | ||
|
||
cin >> tz1 >> tz2; | ||
offset = seconds + (h + tz[tz2] - tz[tz1]) * 3600.0 + m * 60; | ||
date = gmtime(&offset); | ||
|
||
string min = to_string(date->tm_min); | ||
min = min.size() < 2 ? "0" + min : min; | ||
h = date->tm_hour % 12; | ||
h = !h ? 12 : h; | ||
|
||
if (date->tm_hour == 0 && date->tm_min == 0) | ||
{ | ||
output += "midnight\n"; | ||
} else if (date->tm_hour == 12 && date->tm_min == 0) | ||
{ | ||
output += "noon\n"; | ||
} else if (date->tm_hour >= 12) | ||
{ | ||
output += to_string(h) + ":" + min + " p.m.\n"; | ||
} else | ||
{ | ||
output += to_string(h) + ":" + min + " a.m.\n"; | ||
} | ||
} | ||
|
||
printf("%s", output.c_str()); | ||
|
||
return(0); | ||
} |
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
Oops, something went wrong.