Official

A - Count . Editorial by en_translator


For beginners

It is sufficient to count the occurrences of i and j in \(S\). Possible approaches include using a function that counts the number of occurrence of a character in a string, and using a loop.

Sample code

#include <bits/stdc++.h>
using namespace std;

int main() {
	string s;
	cin >> s;
	cout << count(s.begin(), s.end(), 'i') + count(s.begin(), s.end(), 'j') << '\n';
}
#include <bits/stdc++.h>
using namespace std;

int main() {
	string s;
	cin >> s;
	int ans = 0;
	for (char c : s) if (c == 'i' or c == 'j') ans++;
	cout << ans << '\n';
}

posted:
last update: