#include<bits/stdc++.h> using namespace std; string s; int N, need, n, y, res; int main() { cin.sync_with_stdio(0); cin >> N; cin >> s; need = N / 10, y = 0, n = 0; for(int i = 0; i < N; ++i) { if(s[i] == 'T') y++; else n++; if(y + n == need) { if(y == need) res++; y = n = 0; } } cout << res; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | #include<bits/stdc++.h> using namespace std; string s; int N, need, n, y, res; int main() { cin.sync_with_stdio(0); cin >> N; cin >> s; need = N / 10, y = 0, n = 0; for(int i = 0; i < N; ++i) { if(s[i] == 'T') y++; else n++; if(y + n == need) { if(y == need) res++; y = n = 0; } } cout << res; } |