Breaking

Wednesday, 12 July 2017

Unique Count of Winners

                        Unique Count of Winners

Certain number of people play a card game. They play N rounds. The names of the winner in each round is passed as the input to the program.The program must print the unique count of the winners.

Input Format:
The first line contains the values of N.N lines contain the names of the winners.

Output Format:
The first line contains the unique count of winners.

Boundary Conditions:
1 <= N <= 100
Length of  name is from 3 to 100

Example Input/Output 1:
Input:
6
Arun
Bhamini
Arun
Derek
Sahul
Bhamini

Output:
4

 Code:
import java.util.*;
public class Hello {

    public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int i;
Set<String> st=new HashSet<String>();
for(i=0;i<n;i++)
{
   String ip=sc.next();
   st.add(ip);
}
System.out.print(st.size());
}

}

No comments:

Post a Comment

Like