I was doing some programming questions on this website called Kattis. Here is a link to the question I was doing: https://open.kattis.com/problems/datum
While I was trying to solve this, I found out something very, very, very weird.
Before I begin, here are two codes:
First one:
#include <iostream>
#include <ctime>
#include <string>
using namespace std;
int main()
{
//a = day, b = month
string days[7] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
struct tm time;
cin >> time.tm_mday >> time.tm_mon;
time.tm_year = 2009-1900;
time.tm_mon--;
mktime(&time);
cout << days[time.tm_wday] << endl;
return 0;
}
Second one:
#include <iostream>
#include <ctime>
#include <string>
using namespace std;
int main() {
//a = day, b = month
string days[7] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
tm time = {};
cin >> time.tm_mday >> time.tm_mon;
time.tm_year = 2009-1900;
time.tm_mon--;
mktime(&time);
cout << days[time.tm_wday] << endl;
return 0;
}
They are THE EXACT SAME code except the only difference in these two codes is:
struct tm time; // first code
vs
tm time = {}; // second code
NOW, This is what I found very confusing. The first code and the second code give an exact same answer on my console. I checked the type of the result (days[time.tm_wday]) by doing typeid(days[time.tm_wday]).name() as well and both of the answer seem to be exact same.
However, when submitted into Kattis website, it only accepts the second one and doesn't accept the first one.
Now, can anyone tell me what I'm missing here? Why is it only accepting one vs another? Thank you very much!
EDIT: Some information on Kattis: There would be a question where you would have to solve it by programming. It then checks your answer with theirs. If your program outputs the same answers, it "accepts" your solution. If its different, then it doesn't.
For example, lets say the quetion is to calculate the area of a square. It gives couple examples with values.
ex) Case 1: (input: 5 Output: 25).
If your console outputs 25 when inputted 5, then it "accepts" your solution. If it outputs some random number like, 10, then it doesn't accept.
The thing with my program is that it outputs exact same values:
First code outputs: Thursday. Second code outputs: Thursday etc. However only one is considered "correct".