Skip to content

Commit

Permalink
Ad Hoc Problems - Part 2. Time (In progress)
Browse files Browse the repository at this point in the history
  • Loading branch information
Guilherme committed Sep 5, 2018
1 parent adbc02a commit a145ea8
Show file tree
Hide file tree
Showing 15 changed files with 67,473 additions and 24 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"tuple": "cpp",
"typeinfo": "cpp",
"utility": "cpp",
"cstring": "cpp"
"cstring": "cpp",
"map": "cpp"
}
}
111 changes: 111 additions & 0 deletions 1/4/10070.cpp
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);
}
52 changes: 52 additions & 0 deletions 1/4/10339.cpp
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);
}
123 changes: 123 additions & 0 deletions 1/4/10371.cpp
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);
}
53 changes: 30 additions & 23 deletions 1/4/170.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
#include <cstdlib>
#include <algorithm>
#include <iostream>
#include <stack>
#include <queue>
#include <map>
#include <sstream>
#include <iomanip>

using namespace std;

Expand All @@ -27,35 +29,39 @@ void populateMap(map<char, int> &m)
m['T'] = 9;
m['J'] = 10;
m['Q'] = 11;
m['K'] = -1;
m['K'] = 12;
}

class Game
{
private:
int index = 0;
int index;
string last;
string *cards;

public:
Game(string last, int index) : last(last), index(index)
{
this->cards = cards;
}
Game(string last = "", int index = 0)
: index(index), last(last) { }

static Game runGame(stack<string> cards, map<char, int> &m)
static Game runGame(queue<string> clock[],
map<char, int> &m)
{
int index = 0;
int end = 0b111111111111;
int clock = 0;
string last;
int index = 0, pointer;
queue<string> *st = &clock[12];
queue<string> debug[13];
string last = "";

while (end > clock && cards.size())
for(int ii = 0; ii < 13; ii++) {
debug[ii] = clock[ii];
}

while (st->size())
{
index++;
last = cards.top();
clock |= (1 << m[last[0]]);
cards.pop();
last = (*st).front();
st->pop();
pointer = m[last[0]];
st = &clock[pointer];
}

return Game(last, index);
Expand All @@ -77,22 +83,23 @@ int main()

while(true)
{
queue<string> clock[13];
cin >> card[0];

if (card[0] == "#") break;

stack<string> pile;

pile.push(card[0]);
clock[12].push(card[0]);

for (int ii = 1; ii < 52; ii++) {
for (int ii = 50; ii >= 0; ii--) {
cin >> card[ii];
pile.push(card[ii]);
clock[ii % 13].push(card[ii]);
}

Game game = Game::runGame(pile, indexMap);
Game game = Game::runGame(clock, indexMap);
ostringstream ss;
ss << setw(2) << setfill('0') << game.getIndex();

output += to_string(game.getIndex()) + "," + game.getLast() + "/n";
output += ss.str() + "," + game.getLast() + "\n";
}

printf("%s", output.c_str());
Expand Down
Loading

0 comments on commit a145ea8

Please sign in to comment.