+ 3

Code coach : DRIVING LICENCE

New Driver's License You have to get a new driver's license and you show up at the office at the same time as 4 other people. The office says that they will see everyone in alphabetical order and it takes 20 minutes for them to process each new license. All of the agents are available now, and they can each see one customer at a time. How long will it take for you to walk out of the office with your new license? Task Given everyone's name that showed up at the same time, determine how long it will take to get your new license. Input Format Your input will be a string of your name, then an integer of the number of available agents, and lastly a string of the other four names separated by spaces. Output Format You will output an integer of the number of minutes that it will take to get your license. Sample Input 'Eric' 2 'Adam Caroline Rebecca Frank' Sample Output 40 My question now : During input,first thing is NAME but what about ext value i.e. integer value, how to use that?

16th Jan 2020, 11:48 AM
Karan Sharma
Karan Sharma - avatar
8 Réponses
- 1
Perhaps an example will help you understand why we need the number of agents. Taking your example, the candidate starts off as third in the list. If there is only one agent availaible, he tests the first person, which takes 20 minutes, after which the second person can come in. Again, the test takes 20 minutes, and then it's our person's turn. After another 20 minutes, our person leaves, taking 60 minutes in total to get his license. All of the tests were done by the same agent. However, if there are two agents, two persons can be tested simultaneously, so the first two people go in. After 20 minutes, they are both finished, since they did their test at the same time. Now number 3 and 4 may come in. Since our person is third, he can already take his test and is finished after 40 minutes. With three agents, he could already take his test at the start, so it would only take 20 minutes, since three agents can do three people at the same time. I believe you can figure out the rest on your own.
19th Jan 2020, 5:40 PM
Shadow
Shadow - avatar
+ 3
I don't quite get your question. The task states that you receive two strings and one integer as input, so all you have to is declare two string variables and one integer variable and then ask for their values in the correct order, e.g.: std::string name; unsigned int agents; std::string others; std::cin >> name; std::cin >> agents; std::cin >> std::ws; std::getline( std::cin, others ); If that is not what you meant, please clarify your question.
16th Jan 2020, 12:41 PM
Shadow
Shadow - avatar
+ 3
DishaAhuja Shadow thanks of all your responds, i was quiet buzy so i didn't get time to look back at that post. Now into the question, My question was, after inputting our name we have to put no. Of agents, so what point was there to do that. Why we take no. Of agents as input, i don't see any use for that in this code. How i see is, each person before our name gets 20 min. Of time. so, time=time+20. After counting total time, do we have to divide it by no. of agents. If so then look into sample case, its different i guess. Our name starts from E. So it have to come 3rd in list. Therefore, time taken should be 60 min. for 3 person to finish off i guess. And even if we divide 60 by no of agents we will get 60/2 = 30 min. Which is not same as sample output which says 40 minz. If I'm missing something please correct me. And again, glad to have all your responses on my questions. Thankyou!
19th Jan 2020, 4:31 PM
Karan Sharma
Karan Sharma - avatar
+ 3
/*If you wanna do it with cpp, will check this code, i have solved this with 0(n^2) complexity can anyone have other alternative that may solve with smaller time complexity.*/ https://code.sololearn.com/cvjXarff9k5C/?ref=app
30th Dec 2021, 12:21 PM
Shahi Shreshth
Shahi Shreshth - avatar
+ 2
Karan Sharma In this problem state as previously mentioned you need to first input the name with your string. Then the number of agents should be imputted after that an string which can contain 4 words need to be inputted. Then alphabetical sorting should be done to calculate the time for each new license. You should know each take 20 minute so you can initialise time =20 for per person license. Number of agent will divide the work so you need to calculate that too.
16th Jan 2020, 12:39 PM
DishaAhuja
DishaAhuja - avatar
+ 2
As you mentioned C language you can input like this way then your logic of if else and for loop for taking string input char str[30],ch[10]; int num,n,i,a=0; scanf("%s\n",ch); scanf("%d\n",&n); fgets(str, 30, stdin);
16th Jan 2020, 12:42 PM
DishaAhuja
DishaAhuja - avatar
+ 2
#this may help you and I have done in python, don't mind :) #to get myname my_name = input() #to get agent name agents = int(input()) #to get all the list names of people other_names = input() #converting all the string to lost to sort list_of_names = other_names.split() #appending myname to compare list_of_names.append(my_name) #sorting the list as question said, work is done only in alpha order. list_of_names.sort() #getting the index of our name in the list... index = list_of_names.index(my_name) + 1 #if the agents r more than index of our name, work will done soon. #because if 5 agents r thr and thr are only 4 peoples, then my task will get sooner if agents >= index: result = 20 #if that's not the case start decounting the value with index and agent and finallu print the value else: time = index - agents result = 20 + time * 20 #print the result finally... print(result)
13th Oct 2021, 2:57 AM
GURURAJ KL
GURURAJ KL - avatar
0
#I need help to know what's the issue with my code which i made in python. as every test cases got succeeded only the last hidden test case was showing error but don't know why. So please explain me #getting my name myname = input() #getting number of agents agents = int(input()) #getting other people names others = input() #adding my name to the list total = others + " " + myname #sorting the list total = sorted(total.split(" ")) #getting my index by increasing with 1 myindex = total.index(myname) + 1 if(myindex <= agents): print(20) else: print(int(myindex/agents) * 20)
19th Apr 2022, 8:39 AM
Aditya Agarwal
Aditya Agarwal - avatar