Can anyone help me figure out what I am not checking for in my code. I did
this question in c++. I would check if the start time or the end time was
in between the new time slot to see if it was possible or not. No matter
how many tests I came up with for it, it always worked but didn't pass when
I submitted it. Any insight into this would be appreciated!
This is my code for the problem:
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
class Parent
{
public:
int startTime;
int endTime;
};
bool checkAvailability(Parent orig, Parent add)
{
if (orig.startTime <= add.startTime && orig.endTime > add.startTime)
return true;
if (orig.startTime < add.endTime && orig.endTime >= add.endTime)
return true;
if (orig.startTime >= add.startTime && orig.endTime <= add.endTime)
return true;
return false;
}
int main() {
int numTests, section;
bool ret;
std::vector<std::string> result;
std::vector<Parent> CameronTimes;
std::vector<Parent> JamieTimes;
std::string output;
Parent* sec;
std::cin >> numTests;
for (int i = 0; i < numTests; i++)
{
std::cin >> section;
output = "";
sec = new Parent[section];
for (int j = 0; j < section; j++)
{
std::cin >> sec[j].startTime >> sec[j].endTime;
if (j == 0)
{
CameronTimes.push_back(sec[j]);
output += "C";
}
else
{
ret = true;
for (int k = 0; k < CameronTimes.size(); k++)
{
if (checkAvailability(sec[j], CameronTimes[k]))
{
ret = false;
break;
}
}
if (ret)
{
CameronTimes.push_back(sec[j]);
output += "C";
continue;
}
ret = true;
for (int k = 0; k < JamieTimes.size(); k++)
{
if (checkAvailability(sec[j], JamieTimes[k]))
{
ret = false;
break;
}
}
if (ret)
{
JamieTimes.push_back(sec[j]);
output += "J";
}
else
{
output = "IMPOSSIBLE";
break;
}
}
}
result.push_back(output);
delete[]sec;
CameronTimes.clear();
JamieTimes.clear();
}
for (int i = 0; i < result.size(); i++)
{
std::cout << "Case #" << i + 1 << ": " << result[i] << std::endl;
}
result.clear();
}
--
You received this message because you are subscribed to the Google Groups
"Google Code Jam" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/google-code/a85e76d7-ddb1-4a7f-9173-d79cff94435b%40googlegroups.com.