To solve the problem, you need to count the number of characters '.', '!' and '?' in the given string.
Algorithm implementation
Read the input string.
getline(cin, s);The variable is used to count the occurrences of the characters '.', '!' and '?' in the string .
res = 0;
for (i = 0; i < s.size(); i++)
if (s[i] == '.' || s[i] == '!' || s[i] == '?') res++;Print the answer.
printf("%d\n", res);Python implementation
Read the input string.
s = input()The variable is used to count the occurrences of the characters '.', '!' and '?' in the string .
res = 0
for x in s:
if x in ".!?": res += 1Print the answer.
print(res)Python implementation — sum for
Read the input string.
s = input()The variable is used to count the occurrences of the characters '.', '!' and '?' in the string .
res = sum(s.count(char) for char in '.!?')Print the answer.
print(res)