Driver license in c | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Driver license in c

I solved this and, It passes all but the last one , I considered that it might be names started with the same letters What to do ? https://code.sololearn.com/cZabgd66i6h9/?ref=app

22nd May 2023, 4:39 AM
Shimaa
Shimaa - avatar
5 Answers
0
Side note though, I don't think the time math works out in all cases, so that's probably the real issue. Consider when you're 5th and there are 2 agents: your calculation gives 40 minutes, but since you're in the 3rd group it'll be 60 minutes before you're done. My first instinct was to just use (1+order/agent), but that doesn't work either, when order%agent=0. So you might need to do some extra work there.
22nd May 2023, 5:24 AM
Orin Cook
Orin Cook - avatar
+ 2
If it wants you to compare the whole name, there's not much to do in bare C but to brute force it. Your choice comes down to whether you want to use a for loop or a while loop, mostly, and which syntax you think makes it more readable (ternary vs verbose)
22nd May 2023, 5:02 AM
Orin Cook
Orin Cook - avatar
+ 2
Initialize order = 0 instead of 1, then in line 23 add 1 to the formula: time=(1+order/agent)*20; Then you may optionally delete lines 20-22, since the corrected time formula will work for all cases. Consider using the string library function strcmp() for string comparisons so that all characters will get checked if needed. Edit: Now I see you got it fixed while I was composing my answer. Good job! šŸ‘
22nd May 2023, 8:21 AM
Brian
Brian - avatar
0
Orin Cook You were right , that was the mistake , i fixed it and it worked ! šŸ™
22nd May 2023, 8:03 AM
Shimaa
Shimaa - avatar
0
I know it's too late to answer this since you have done the challenge, but.. You can remove all names that comes after the given name in a sorted group, in another lists(Idk if C has this one because I'm not a C programmer). This helps you to solve the problem easily. This is how I solve this problem in Python. Idk if this one works for C, but I hope youll be solving even harder problems like this in the future.
23rd May 2023, 4:46 AM
Dragon RB
Dragon RB - avatar