String Analyzer
EasyPractice library · +10 XPstringscountingsimple parsing
Given a string $S$ consisting of lowercase English letters, perform the following operations:
- Count the total number of characters in $S$.
- Count the number of occurrences of the character 'a' in $S$.
- Count the number of occurrences of the character 'z' in $S$.
- Determine if the first character of $S$ is the same as the last character of $S$. Print these four values on a single line, separated by spaces, in the order specified above.
Input
A single line containing the string $S$ (1 <= |S| <= 1000).
Output
A single line with four space-separated integers: total length, count of 'a', count of 'z', and 1 if the first and last characters are the same, 0 otherwise.
Constraints
|S| <= 1000
Time limit 1 s (native code; slower languages get more)Memory 256 MB15 hidden tests
Example 1
Input
banana
Output
6 3 0 0
String 'banana': length 6, 3 'a's, 0 'z's, first 'b' != last 'a'.
Example 2
Input
azaza
Output
5 3 2 1
String 'azaza': length 5, 2 'a's, 2 'z's, first 'a' == last 'a'.
Hints
# Read the input from stdin and print the answer.
import sys
def main():
data = sys.stdin.read().split()
# your code here
main()
Example 1 input
banana
Example 2 input
azaza