Question to the test ''New driver's license'' | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Question to the test ''New driver's license''

Hello Everybody! Can somebody look at my code to the test ''New driver's license'' and say what is wrong with it, it passed 4 test cases except 1 and I don't know where I made a bug. Will be happy for any help. ;) --------------------------------------------------------------------------------------------------------- #include <stdio.h> #include <stdlib.h> #include <string.h> int main(void) { char name[20]; char other[80]; int agents, place = 1; scanf("%s %d\n", name, &agents); fgets(other, 80, stdin); if(name[0] > other[0]) place++; for(int i = 0; i < strlen(other); i++) { if(other[i] == ' ') { if(name[0] > other[i + 1]) place++; } } printf("%d", 20 + place * 20 - agents * 20); return 0; }

16th Jan 2022, 10:00 PM
🇺🇦 Dmytro 🇺🇦
🇺🇦 Dmytro 🇺🇦 - avatar
1 Answer
+ 4
The final formula is incorrect. Since place is your own place in line, it should be reduced by 1 to represent how many are before you. Also the number of persons in line should be divided by the number of agents, as there could be multiple more customers than agents. Here is my recommended correction: printf("%d", 20*(1 + (place-1)/agents));
16th Jan 2022, 11:01 PM
Brian
Brian - avatar