New Driver's License Code | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

New Driver's License Code

Hi, I made this code using C++ and I tested it on a different app and everything seemed fine. However, running it in the testing environment I get an error that says timeout: the monitored command dumped core. What does this mean? I researched it but I haven't gotten a clear answer as to what I did wrong. #include <iostream> #include <string> #include <sstream> #include <vector> #include <algorithm> using namespace std; void split_q_string(vector <string> &q, string &qString){ string s_qString; stringstream split(qString); while (getline(split, s_qString, ' ')){ q.push_back(s_qString); } } void arrVector(vector <string> &q){ sort(q.begin(), q.end()); } void printVector(vector <string> &q){ for(int i=0; i<5; i++){ } } int calcTime(vector <string> &q,int const &a_num,string const &name){ string odd[3]; string even[3]; int counter=0; int j=0; for(int i=0; i<5; i++){ (i%2==0)? even[counter] = q[i] : odd[counter] = q[i]; j++; if(j%2==0){ counter++; } } for(int i=0; i<3; i++){ if(name==even[i]){ return i; } if(name==odd[i]){ return i; } } return -1; } int main(){ string name,p_inQueue; int noAgents, result; getline(cin,name); cin>>noAgents; getline(cin, p_inQueue); vector <string> QueueList; split_q_string(QueueList,p_inQueue); QueueList.push_back(name); arrVector(QueueList); printVector(QueueList); result=calcTime(QueueList,noAgents, name); result *= 20; result += 20; cout<<result; return 0; } P.S I know it's not very efficient right now, but this was my first time doing it as a challenge

4th Nov 2020, 7:50 PM
Karo A
Karo A - avatar
1 Answer
+ 1
While I do not immediately see why it gets a timeout error, I would recommend re-thinking the solution. The code is ambitiously over-designed. It is unnecessary to model the whole operation just to find the answer. Hint: Count how many names are alphabetically in line ahead of you, then calculate the wait time based on that number. There is no need to sort or use data structures.
4th Nov 2020, 8:31 PM
Brian
Brian - avatar