#45. 字符串去重并映射零值
字符串去重并映射零值
String Map Zero Values
Background
Congcong is learning how to process and organize data. He encountered an interesting problem that requires him to organize a group of strings and assign a specific initial value to each unique string.
Problem Description
Given an array of strings, return a Map<String, Integer> containing a key for every different string in the array, always with the value . For example, the string "hello" makes the pair "hello":0. We'll do more complicated counting later, but for this problem the value is simply .
Input Format
Input is given from standard input in the following format.
Multiple strings, separated by spaces.
Output Format
Output is printed to standard output in the following format.
A
Map<String, Integer>, represented in JSON format, where keys are unique strings and values are all .
Sample
"a" "b" "a" "b"
{"a": 0, "b": 0}
"a" "b" "a" "c" "b"
{"a": 0, "b": 0, "c": 0}
"c" "b" "a"
{"a": 0, "b": 0, "c": 0}
Sample Explanation
For the first sample input "a" "b" "a" "b", the unique strings in the array are "a" and "b". Therefore, the output map contains these two keys, with their values both set to , i.e., {"a": 0, "b": 0}.
Constraints
Time limit for each test case is second, and memory limit is KiB.