Can anyone help me solve the 4th test case. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Can anyone help me solve the 4th test case.

import java.util.*; public class Program { public static void main(String[] args) { Scanner in = new Scanner(System.in); String name = in.next(); int a = (int)(name.charAt(0)); int min=20; int agents = in.nextInt(); String others = in.next(); others += in.nextLine(); String[] ppl = others.split("[\\s]"); int c = ppl.length; if(agents>1){ c =c /agents; } for(int i=0; i<c; i++){ int b = (int)(ppl[i].charAt(0)); if(a>b){ min += 20; } else if(a<=b){ min = min; } else{ continue; } } System.out.print(min); } }

12th Aug 2020, 9:15 AM
Sunitha
9 Answers
0
Here's a simple, easy to understand solution https://code.sololearn.com/c28tBnN1d9ss/?ref=app
12th Aug 2020, 11:19 AM
Namit Jain
Namit Jain - avatar
+ 8
Actually ,the code coach solutions which you have solved can be viewed only by you ,copy the code into the code playground and share that link to us:)
12th Aug 2020, 9:50 AM
chaithra Gowda
chaithra Gowda - avatar
+ 4
Sunitha Avoid Youtube and other websites, like Newboston, tutorial points, official docs. Instead take some course on Udemy. If you dont want to pay the price then the same content will be available in “freetutorialus” (torrent files), but may take time downlaoding. But Java Brains (youtube channel) is an exception. Its a must for JEE (no core Java tought here). I myself learned from Newboston, youtube videos, tutorialspoint ,javapoint and many others. But later understood that most are outdated and unorganized. You may get stuck somewhere after each learning. Summary: Core java: any Udemy course *Advanced Java: Java Brains (includes CRUD projects) *Spring and Hybernate (Java framework and ORM respectively): Java Brains *Angular2/4/5: Udemy (better find a Angular2 Spring project and learn along)
14th Aug 2020, 5:17 AM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 2
Sunitha Google
12th Aug 2020, 11:38 AM
Namit Jain
Namit Jain - avatar
0
Pls Share your attempt here...
12th Aug 2020, 9:44 AM
Jayakrishna 🇮🇳
0
Oh okay. All the test cases are correct but only 4th test case is wrong...
12th Aug 2020, 9:52 AM
Sunitha
0
Sunitha if you made any changes, then give a reply or tag someone to inform them. Otherwise they don't get notification about your changes.. Ok Your program failing when number of agents 2 cases. And actually you missing sorting input.. Persons are called in alphabetical order. So when for ex: c =c /agents; for(int i=0; i<c; i++) by these here, If person is C, agents 3 persons A, E, D, B then here c = 4/3 =1 so you are calculating for A, only so you get correct answer 20 since 0 to 1 iterations A>C false.. But if order input is C, E, A, D, B then you get 40 answer which is wrong... So sort input for ppl first then make changes accordingly.. Hope you find solution.. Reply if you struck again..
12th Aug 2020, 11:09 AM
Jayakrishna 🇮🇳
0
Namit Jain Can you please tell me where I can learn Data structures with java in an easy and simple way...
12th Aug 2020, 11:25 AM
Sunitha
0
Sunitha I can't say easy way but if you want video tutorials about java SE, I recommend to check Telusko learnings channel.. His teachings are good.. Sites: check javagoals.com, java point.com,.. https://www.opensourceforu.com/2015/06/data-structures-made-easy-with-java-collections/ https://www.tutorialspoint.com/java/java_data_structures.htm https://www.javatpoint.com/data-structure-tutorial about books, hope this may give some information to you... https://dev.to/javinpaul/11-best-java-books-for-beginners-and-senior-developers-4b5
15th Aug 2020, 11:31 AM
Jayakrishna 🇮🇳