SBANK - Sorting Bank Accounts Spoj editorial or solution - UCS - Unleash-Coding-Skills

Thursday, 26 April 2018

SBANK - Sorting Bank Accounts Spoj editorial or solution - UCS

code { background: hsl(220, 80%, 90%); } pre { display: inline; }

SBANK - Sorting Bank Accounts

The link for this problem is:

This is simple sorting problem is done using JAVA. It is best problem for you to learn and implement java collections.The following is the solution for the problem SBANK - Sorting Accounts done using JAVA.

import java.io.*;
import java.lang.*;
import java.util.*;
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
   Map<String,Integer> mp = new HashMap<>();
     TreeSet <String> st = new TreeSet<>();
    int t;
        Scanner s = new Scanner(System.in);
        t= s.nextInt();
        for(int i=0;i<t;i++)
        {
            mp.clear();
            st.clear();
            int n;
            n=s.nextInt();
               String s1;
             s1=s.nextLine();
            for(int j=0;j<n;j++)
            {
                s1=s.nextLine();
              st.add(s1);
                if(mp.get(s1)!=null)
                {
                    int val = mp.get(s1);
                    val++; 
                    mp.put(s1,val);
                }
                else
                {
                    mp.put(s1,1);
                }
            }
            Iterator<String>itr = st.iterator();
            while(itr.hasNext())
            {
              s1 = itr.next();
                System.out.println(s1+" "+mp.get(s1));
            }
     System.out.println();
        }
}
}


Try this latest problem in SPOJ available with solution:


DIVSTR - Divisible Strings:

https://www.unleashcodingskills.com/2018/05/divstr-divisible-strings-editorial-spoj.html

Happy Coding...........


Feel Free to make comments......

No comments:

Post a comment