under the kitchen

Topic description

Niu Niu wants to try some new dishes, each dish needs some different ingredients, and asks how many different ingredients need to be prepared to complete all the dishes.

Enter description:

Each input contains 1 test case. The i-th line of each test case indicates which materials are needed to complete the i-th cooking. Each material is separated by spaces. The input only contains uppercase English letters and spaces. The input file does not exceed 50 lines, and each line does not exceed 50 characters.

Output description:

Output a line with a number indicating how many different ingredients are needed to complete all recipes.
Example 1

enter

BUTTER FLOUR
HONEY FLOUR EGG

output

4


 1 import java.util.HashSet;
 2 import java.util.Scanner;
 3 import java.util.Set;
 4 
 5 /**
 6  * 
 7  * 下厨房
 8  *   用set去重复 
 9  * @author Dell
10  *
11  */
12 public class Main {
13     public static void main(String[] args) {
14         Scanner sc = new Scanner(System.in);
15         Set<String> set = new HashSet();
16 
17         while (sc.hasNextLine()) {
18             String str = sc.nextLine().trim();
19             String[] array = str.split(" ");
20             for (int k = 0; k < array.length; k++) {
21                 set.add(array[k]);
22             }
23         }
24         System.out.println(set.size());
25     }
26 }

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325141560&siteId=291194637