#C12613. First Non-Repeating Character
First Non-Repeating Character
First Non-Repeating Character
Given a string s
, your task is to find and return the first character that does not repeat anywhere in the string. If every character appears at least twice, print All characters are repeating
.
Note that the search is case-sensitive, i.e., 'a' and 'A' are considered different characters.
The algorithm follows these steps:
- Count the occurrence of each character in the string.
- Iterate over the string to find the first character with count equal to 1.
- If no such character exists, output the message "All characters are repeating".
The frequency, f, of each character x in the string can be expressed as \( f(x) \). We need to find the first \( x \) such that \( f(x) = 1 \).
inputFormat
The input consists of a single line containing the string s
. The string may be empty.
outputFormat
Output a single line with the first non-repeating character. If every character repeats, output All characters are repeating
.
aabc
b