I found this online judge program today and I thought I would test it.
But when I tested it with a program that runs perfectly in Dev-c++ I got Runtime error. Why isn't there
some kind of error reporting on this stuff. I have no idea what is causing this error.
Please take a look at the source code and help me find it. It's so confusing and irritating and I really want to know
why. I use c++ on windows.
Thanks
Code: Select all
#include <iostream>
using namespace std;
enum Type {
EXPRESS,
ORDINARY
};
int addTrain (int queue[], int &pos, int leave)
{
pos++;
queue[pos-1] = leave;
return 0;
}
int main()
{
int ae, ao, le, lo, t;
int selType, selNum;
int i, j;
const int SIZE = 20;
int expQueue[SIZE], ordQueue[SIZE];
int expWait[SIZE], ordWait[SIZE];
int nExpWaits = 0, nOrdWaits = 0;
int expLen=0, ordLen=0;
int expTrain, ordTrain;
for (i=0; i<SIZE; i++) {
expWait[i] = 0;
ordWait[i] = 0;
expQueue[i] = 0;
ordQueue[i] = 0;
}
cin >> ae >> ao >> le >> lo >> t;
addTrain(expQueue, expLen, le);
selType = EXPRESS; selNum = expLen-1;
cout << "0 0 0" << endl;
for (i=1; i<=t; i++) {
if (i % ae == 0) {
addTrain (expQueue, expLen, le);
}
if (i % ao == 0) {
addTrain (ordQueue, ordLen, lo);
}
if (selType == EXPRESS && expQueue[selNum] > 1) {
expQueue[selNum]--;
}
else if (selType == ORDINARY && ordQueue[selNum] > 1) {
ordQueue[selNum]--;
} else {
expTrain = -1;
for (j=0; j<expLen; j++) {
if (expQueue[j] > 1 && j != selNum) {
expTrain = j;
break;
}
}
ordTrain = -1;
for (j=0; j<ordLen; j++) {
if (ordQueue[j] > 0 && j != selNum) {
ordTrain = j;
break;
}
}
if (expTrain >= 0) {
selType = EXPRESS;
selNum = expTrain;
}
else if (ordTrain >= 0) {
selType = ORDINARY;
selNum = ordTrain;
}
}
nExpWaits = 0;
nOrdWaits = 0;
for (j=0; j<expLen; j++) {
if (!(j == selNum && selType == EXPRESS) && expQueue[j] > 1) {
if (i != t) expWait[j]++;
nExpWaits++;
}
}
for (j=0; j<ordLen; j++) {
if (!(j == selNum && selType == ORDINARY) && ordQueue[j] > 1) {
if (i != t) ordWait[j]++;
nOrdWaits++;
}
}
if (i % ae == 0 || i % ao == 0) {
cout << i << " " << nExpWaits << " " << nOrdWaits << endl;
}
}
cout << "0" << endl;
int avgExp=0, avgOrd=0, avgAll=0;
for (i=0; i<expLen; i++) {
avgExp += expWait[i];
}
for (i=0; i<ordLen; i++) {
avgOrd += ordWait[i];
}
avgAll = (avgOrd + avgExp) / (ordLen + expLen);
avgOrd /= ordLen;
avgExp /= expLen;
cout << avgExp << " " << avgOrd << " " << avgAll << endl << "0" << endl;
for (i=0; i<expLen; i++) {
cout << "E" << (i+1) << " " << expWait[i] << endl;
}
for (i=0; i<ordLen; i++) {
cout << "O" << (i+1) << " " << ordWait[i] << endl;
}
return 0;
}