ABC150B - Count ABC
#include <iostream> #include <string> using namespace std; int main(void) { int n, pos = 0, ans = 0; string s; cin.tie(0); ios::sync_with_stdio(false); cin >> n; cin >> s; while (s.find("ABC", pos) != string::npos) { ans++; pos = s.find("ABC", pos) + 3; } cout << ans << "\n"; return 0; }
pos の位置をfind内に書いており、1WA。。