Okay, new entry to this post.
I got a code that is faster than those previous two (probably fast enough this time) but it gives incorrect outputs in some results and I have no idea why.
Some examples:
Input: 13 0 12113940
Output (my program): 4071600
Output (correct): 4071584
Difference of 16 bells (probably something related to 00:00 h because 12g + 4a = 16)
I believe this is the cause but tested it with smaller numbers and had no problem (4071600 is divisible by 60 and not for 1440):
1 2 3 4 5 6 7 8 9 10 11 12
|
if (ct == 60) {
a -= 4;
if (h == 12) angelus -= 100;
if (h != 12) {
if (h == 0) g -= 12;
if (h > 0 and h < 12) g -= h;
if (h > 12) {
int ch = h-12;
g -= ch;
}
}
}
|
Input: 12 30 47625111
Output (my program): 16007421
Output (correct): 16007332
Difference of 89 bells (no idea how why such big range and why it happened)
Lastly, the code (I know it is horrible, no need to tell me);
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
|
#include <iostream>
using namespace std;
int main () {
int h, m, t;
while (cin >> h >> m >> t) {
int a = 0, g = 0, angelus = 0, total = 0;
while (t > 0) {
if (t >= 1440) {
int nd = t/1440;
int cd = t;
t = t%1440;
for (int i = 0; i < nd; ++i) {
a += 240;
g += 144;
angelus += 100;
}
if (cd == 1440) {
a -= 4;
if (h == 12) angelus -= 100;
if (h != 12) {
if (h == 0) g -= 12;
if (h > 0 and h < 12) g -= h;
if (h > 12) {
int ch = h-12;
g -= ch;
}
}
}
}
if (t >= 60 and t < 1440) {
int nh = t/60;
int ct = t;
m += (60*nh);
t = t%60;
for (int i = 0; i < nh; ++i) {
if (h == 12) {
angelus += 100;
a += 10;
}
if (h != 12) {
a += 10;
if (h == 0) g += 12;
if (h > 0 and h < 12) g += h;
if (h > 12) {
int ch = h-12;
g += ch;
}
}
if (m >= 60) {
m -= 60;
h += 1;
if (h == 24) h = 0;
}
}
if (ct == 60) {
a -= 4;
if (h == 12) angelus -= 100;
if (h != 12) {
if (h == 0) g -= 12;
if (h > 0 and h < 12) g -= h;
if (h > 12) {
int ch = h-12;
g -= ch;
}
}
}
}
if (t < 60) {
if (m%15 == 1 and t >= 15) {
m += 15;
t -= 15;
}
else {
++m;
--t;
}
if (m >= 60) {
m -= 60;
h += 1;
if (h == 24) h = 0;
}
if (h == 12 and m == 1) {
angelus += 100;
a += 4;
}
if (h != 12 and m == 1) {
a += 4;
if (h == 0) g += 12;
if (h > 0 and h < 12) g += h;
if (h > 12) {
int ch = h-12;
g += ch;
}
}
if (m == 16) a += 1;
if (m == 31) a += 2;
if (m == 46) a += 3;
}
}
total += a+g+angelus;
cout << total << endl;
}
}
|
If anyone has an idea of what is happening I would like to know, meanwhile I will try to figure myself what is wrong in the code. My previous two programs give me correct output so it means that the error in this program has to be in the new added code lines.