Unique count of Winners - java - Spicy Coders

Recent

Wednesday, July 12, 2017

Unique count of Winners - java

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

Coding:

import java.util.*;
public class Hello
 {
public static void main(String[] args)
{
Scanner s=new Scanner(System.in);
int n=s.nextInt();
HashSet<String> h=new HashSet<>(n);
for(int i=0;i<n;i++)
h.add(s.next());
System.out.println(h.size()); 
}

}

No comments:

Post a Comment