fork(1) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static class Employee{
  11. String name;
  12. int salary;
  13.  
  14. Employee(String name,int salary){
  15. this.name=name;
  16. this.salary=salary;
  17. }
  18. }
  19. public static class EmpComparator extends Comparator<Employee>{
  20. public int compare(Employee o1,Employee o2){
  21. if(o1.name==o2.name){
  22. if(o1.salary>o2.salary)
  23. return 1;
  24. else
  25. return 0;
  26. }
  27. else if(o1.name>o2.name)
  28. return 1;
  29. else
  30. return 0;
  31. }
  32. }
  33. public static void main (String[] args) throws java.lang.Exception
  34. {
  35. Scanner sc= new Scanner(System.in);
  36. int t= sc.nextInt();
  37. while(t-->0){
  38. Set<Employee> hash= new HashSet<Employee>();
  39. int x=sc.nextInt();
  40. while(x-->0){
  41. String z=sc.next();
  42. int b=sc.nextInt();
  43. hash.add(new Employee(z,b));
  44. }
  45. Collections.sort(hash,new EmpComparator());
  46. Iterator it= hash.iterator();
  47. while(it.hashNext()){
  48. Employee e=it.next();
  49. System.out.print(e.name+" "+e.salary);
  50. }
  51. System.out.println();
  52. }
  53. }
  54. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
2
2
xbnnskd 100 geek 50
2
shyam 50 ram 50
compilation info
Main.java:19: error: no interface expected here
	public static class EmpComparator extends Comparator<Employee>{
	                                                    ^
Main.java:27: error: bad operand types for binary operator '>'
			else if(o1.name>o2.name)  
			               ^
  first type:  String
  second type: String
Main.java:45: error: no suitable method found for sort(Set<Employee>,EmpComparator)
			Collections.sort(hash,new EmpComparator());
			           ^
    method Collections.<T#1>sort(List<T#1>) is not applicable
      (cannot infer type-variable(s) T#1
        (actual and formal argument lists differ in length))
    method Collections.<T#2>sort(List<T#2>,Comparator<? super T#2>) is not applicable
      (cannot infer type-variable(s) T#2
        (argument mismatch; Set<Employee> cannot be converted to List<T#2>))
  where T#1,T#2 are type-variables:
    T#1 extends Comparable<? super T#1> declared in method <T#1>sort(List<T#1>)
    T#2 extends Object declared in method <T#2>sort(List<T#2>,Comparator<? super T#2>)
Main.java:47: error: cannot find symbol
			while(it.hashNext()){
			        ^
  symbol:   method hashNext()
  location: variable it of type Iterator
Main.java:48: error: incompatible types: Object cannot be converted to Employee
				Employee e=it.next();
				                  ^
5 errors
stdout

Standard output is empty