公式
A - Count . 解説
by
A - Count . 解説
by
cn449
初心者の方へ
- プログラミングの学習を始めたばかりで何から手をつけるべきかわからない方は、まずは practice contest の問題A「Welcome to AtCoder」をお試しください。言語ごとに解答例が掲載されています。
- また、プログラミングコンテストの問題に慣れていない方は、 AtCoder Beginners Selection の問題をいくつか試すことをおすすめします。
- C++入門 AtCoder Programming Guide for beginners (APG4b) は、競技プログラミングのための C++ 入門用コンテンツです。
- Python入門 AtCoder Programming Guide for beginners (APG4bPython) は、競技プログラミングのための Python 入門用コンテンツです。
\(S\) に含まれる i の個数と j の個数を足し合わせればよいです。特定の文字が文字列に含まれる回数を求める関数を使う方法や、ループを用いて答えを数え上げる方法があります。
実装例
#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';
}
投稿日時:
最終更新: