#C5358. First Non-Repeating Character
First Non-Repeating Character
First Non-Repeating Character
Given a string s, your task is to find the first character that does not repeat anywhere in the string. If no such character exists, output an underscore '_'
. For example, in the string "leetcode", the first non-repeating character is 'l'
, while in "aabbcc" every character repeats so the answer is '_'
.
The problem requires reading input from standard input (stdin) and printing the result to standard output (stdout).
Note: The solution should use appropriate algorithms and data structures to achieve efficient performance.
Mathematically, if we define a function \( f(s) \) such that
[ f(s)= \begin{cases} c & \text{if } c \text{ is the first non-repeating character in } s, \ '_' & \text{if every character repeats.} \end{cases} ]
then your program should output \( f(s) \) after processing the given input string.
inputFormat
The input consists of a single line containing the string s. The string may include letters, digits, or other characters. It is guaranteed that the string will not exceed 104 characters.
Input is given via standard input (stdin).
outputFormat
Output a single character, which is the first non-repeating character in the string s. If there is no such character, output an underscore '_'
.
Output should be written to standard output (stdout).
## sampleleetcode
l