New Driver's License (Can any one explain me the question?) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

New Driver's License (Can any one explain me the question?)

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

12th Aug 2022, 4:23 AM
Gokul Ananth
Gokul Ananth - avatar
4 Answers
+ 2
What if there is only 1 agent? Does that make a problem in your line ((count/n)+1)*20?
12th Aug 2022, 5:35 AM
Ausgrindtube
Ausgrindtube - avatar
+ 2
Use s[i].equals( str) // for string comparisons.. Instead of s[i]==str
12th Aug 2022, 11:40 AM
Jayakrishna 🇮🇳
+ 1
import java.util.*; public class Program { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String str = sc.nextLine(); // get the name as String int n = sc.nextInt(); // number of agents available sc.nextLine(); String str1 = sc.nextLine(); // get the name 4 people at the office as String String c[] = str1.split("\\s+"); // split the name of 4 people w.r.t. space and store it in an array String s[] = new String[c.length+1]; // create a new array with respect to previous array+1 to include your name for(int i=0; i<c.length+1; i++){ // insert the values into array if(i==c.length){ s[i]=str; break; } s[i] = c[i]; } Arrays.sort(s); // sort the array in ascending order (alphabetical order) int count=1; for(int i=0; i<s.length; i++){ // to find the position of your name in the array if(s[i]==str){ break; // if name arrives, the loop will be terminated } count++; } /* the next step is done w.r.t no. of agents. time for each person to get a driving license is 20 minutes. And one agent can see one person at a time. if the no. of employee is two, my name is in 4th position, it takes 40 minutes as 1st person will goto one agent and 2nd will goto other agent with the time period 20 minutes. So, the 3rd goes to one agent and you goes to other agent with the time period 20. Hence, 20+20=40. */ int ans = 0; if(count%n!=0){ // if the position of the name is divided by no. of agents, the remainder is not 0, add the quotient with 1 and multiply by 20. ans = ((count/n)+1)*20; } else{ // if the position of the name is divided by no. of agents, the remainder is 0, multiply the quotient by 20. ans = (count/n)*20; } System.out.print(ans); }
12th Aug 2022, 4:43 AM
Gokul Ananth
Gokul Ananth - avatar
+ 1
Nope bro... It will not make any change in the process...
12th Aug 2022, 10:40 AM
Gokul Ananth
Gokul Ananth - avatar